note 88137 added to function.str-replace
| From: | robbiesmith79 at gmail dot com | Date: | Mon, 12 Jan 2009 15:35:13 +0000 |
| Subject: | note 88137 added to function.str-replace | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149094@lists.php.net to get a copy of this message | ||
Came across a difference between Excel 2003 vs Excel 2007 documents and the different formats they
push out csv files.
In 2007, the format pushes out the chr(13) instead of the \n in 2003.
Just as a safety precaution, do a quick replace on the fread contents from the excel file :-)
$lineseparator = "\n";
// check for the user supplied list type format
if ($_REQUEST['listtype'] == "csv")
$fieldseparator = ",";
elseif ($_REQUEST["listtype"] == "tab")
$fieldseparator = "\t";
// replaces the carriage return with the \n character
$csvcontent = str_replace(chr(13), $lineseparator,$csvcontent);
// then
foreach(split($lineseparator,$csvcontent) as $line) {
$lines++;
if ($lines >1) { // skips header row
$line = trim($line," \t");
$line = str_replace("\r","",$line);
// split the line up
$linearray = explode($fieldseparator,$line);
// take care of The "Billy" the kid issue
for ($x = 0; $x<sizeof($linearray); $x++) {
$linearray[$x] = str_replace('""','^',$linearray[$x]);
$linearray[$x] = str_replace('""','^',$linearray[$x]);
$linearray[$x] = str_replace('"','',$linearray[$x]);
$linearray[$x] = str_replace('"','',$linearray[$x]);
$linearray[$x] = str_replace('^','"',$linearray[$x]);
}
// then reference each element in order of the line by array and key
// echo $linearray[0]; //, etc.
}
}
Happy Coding!
----
Server IP: 69.147.83.197
Probable Submitter: 72.186.65.219
----
Manual Page -- http://www.php.net/manual/en/function.str-replace.php
Edit -- https://master.php.net/note/edit/88137
Del: integrated -- https://master.php.net/note/delete/88137/integrated
Del: useless -- https://master.php.net/note/delete/88137/useless
Del: bad code -- https://master.php.net/note/delete/88137/bad+code
Del: spam -- https://master.php.net/note/delete/88137/spam
Del: non-english -- https://master.php.net/note/delete/88137/non-english
Del: in docs -- https://master.php.net/note/delete/88137/in+docs
Del: other reasons-- https://master.php.net/note/delete/88137
Reject -- https://master.php.net/note/reject/88137
Search -- https://master.php.net/manage/user-notes.php