Index: trunk/extensions/ExternalData/ED_Utils.php |
— | — | @@ -70,11 +70,11 @@ |
71 | 71 | $arg = preg_replace ( "/\s\s+/", ' ', $arg ); // whitespace |
72 | 72 | |
73 | 73 | // Split text on commas, except for commas found within quotes |
74 | | - // and parentheses. Code copied from: |
| 74 | + // and parentheses. Code based on: |
75 | 75 | // http://stackoverflow.com/questions/1373735/regexp-split-string-by-commas-and-spaces-but-ignore-the-inside-quotes-and-parent#1381895 |
76 | 76 | $pattern = <<<END |
77 | 77 | / |
78 | | - [,\s]++ |
| 78 | + [,]++ |
79 | 79 | (?=(?:(?:[^"]*+"){2})*+[^"]*+$) |
80 | 80 | (?=(?:(?:[^']*+'){2})*+[^']*+$) |
81 | 81 | (?=(?:[^()]*+\([^()]*+\))*+[^()]*+$) |
— | — | @@ -319,11 +319,17 @@ |
320 | 320 | } |
321 | 321 | fclose( $fp ); |
322 | 322 | //} |
323 | | - // now "flip" the data, turning it into a column-by-column |
324 | | - // array, instead of row-by-row |
| 323 | + // Get header values, if this is 'csv with header' |
325 | 324 | if ( $has_header ) { |
326 | 325 | $header_vals = array_shift( $table ); |
| 326 | + // On the off chance that there are one or more blank |
| 327 | + // lines at the beginning, cycle through. |
| 328 | + while ( count( $header_vals ) == 0 ) { |
| 329 | + $header_vals = array_shift( $table ); |
| 330 | + } |
327 | 331 | } |
| 332 | + // Now "flip" the data, turning it into a column-by-column |
| 333 | + // array, instead of row-by-row. |
328 | 334 | $values = array(); |
329 | 335 | foreach ( $table as $line ) { |
330 | 336 | foreach ( $line as $i => $row_val ) { |