sql - PHP detect Windows or Unix format of csv or txt file? -
i using php upload file server , pass path sql stored procedure bulk insert
import file sql table.
in sql know how bulk insert work both windows , unix based csv , txt files need know format is.
i hoping figure out in php , pass stored procedure. can update rowterminator
accordingly.
is there way in php detect if csv or txt windows or unix based?
any great.
thanks!
get first line file. check if last 2 chars or last char are:
\r\n
-> windows\n
-> unix
example:
$lines = file('test.csv'); $line = $lines[0]; switch(true) { case substr($line, -2) === "\r\n" : echo "windows"; break; case substr($line, -1) === "\n" : echo "unix"; break; default : // pigs can fly echo "unknown line ending" break; }
Comments
Post a Comment