Regex: Parsing after 16 occurrences of a character?
/* Edited to make sense! */
I 900 lines of this:
;745;ref;name;Adress;zipcode;;mobphone;;;;;;;;;
i want 900 lines of this:
array(
'',
745,
'ref',
'name',
'adress',
'zipcode',
'',
'mobphone'
etc.开发者_如何学Go.
)
Some of the lines appear to be concated to one, so it's one long instead of two short. I need to use PHP's split() function to split the lines after every 16th semicolon character, that's what i need your help with.
I don't know if this will help you, but PHP already contains functionality which allows you to parse a CSV file. The fgetcsv()
function will read a CSV file line by line. It returns an array containing the values of each field in the current row.
In your case, you would need to tell it to use a semi-colon instead of a comma as the field delimiter.
$fp = fopen('file.csv', 'r');
while ($line = fgetcsv($fp, 0, ';')){
$firstField = $line[0];
$secondField = $line[1];
//...
}
Take a look at explode: http://php.net/manual/en/function.explode.php
精彩评论