php - Regex Unclosed Quote -
I am trying to find a way to read a CSV with the return in PHP. The problem occurs when you read the file like this:
if (($ handle = fopen ($ file, "r")) == incorrect {while (($ data = Fgetcsv ($ handle, 1000, ",")) == incorrect) {line data ...}}
If you have a retired CSV, then it does not work It just sees returns as a new line
I thought there should be a regex to check without any quotation marks, but I do not know anything like that any thoughts?
Since it seems that the built-in fgetcsv does not handle the CSV standard correctly, Suggestions for - Here's one of them:
From
The handling of PHP's CSV is non-standard and is contrasted with RFC4180, thus fgetcsv () handling properly With the file like this example ...
There is a quick and dirty RFC analog sensation of CSV creation and parsing:
D> & lt; Php function array_to_csvstring ($ item, $ CSV_SEPARATOR = ';', $ CSV_ENCLOSURE = '"', $ CSV_LINEBREAK =" \ n ") {$ string = ''; $ o = array (); foreach ($ as item $ Item) {if (striips ($ item, $ CSV_ENCLOSURE) == false!) {$ Items = str_replace ($ CSV_ENCLOSURE, $ CSV_ENCLOSURE $ CSV_ENCLOSURE, $ items.);} If ((stripos ($ items, $ CSV_SEPARATOR) == False!) || (Strippos ($ item, $ CSV_ENCLOSURE $!) == incorrect) || (Strippos ($ item, $ csv _LINEBREAK! == incorrect)) {$ item = $ CSV_ENCLOSURE $ item $ CSV_ENCLOSURE; } $ O [] = $ item;} $ String = implode ($ CSV_SEPARATOR, $ o). $ CSV_LINEBREAK; return $ string;} function csvstring_to_array (& amp; $ string; $ CSV_SEPARATOR = ';', $ CSV_ENCLOSU RE = '' ', $ CSV_LINEBREAK = "\ n") {$ o = array (); $ cnt = strlen ($ string); $ esc = false; $ escesc = false; $ number = 0; $ i = 0 ; While ($ i & lt; $ cnt) {$ s = $ string [$ i], if ($ s == $ CSV_LINEBREAK) {if ($ esc) {$ o [$ number] = $ s;.} Else {$ i ++; break;} elseif ($ s == $ CSV_SEPARATOR) {if ($ esc) {$ o [$ number] = $ ($ Escesc) {$ o [$ num] $$ CSV_ENCLOSURE; $ Escesc = false;} if ($ esc) {$ esc = false; $ Escesc = true;} and {$ esc = true; $ Escesc = false;}} and {if ($ escesc) {$ o [$ num]. = $ CSV_ENCLOSURE; $ Escesc = false;} $ o [$ num]. $ $ S;} $ i + +; } // $ string = substr ($ string, $ i); $ O flame; }? & Gt;
Comments
Post a Comment