Sample Input:
$document='(400, 530); 6.9; 5.7; 5.0; ...
(500, 530); 7.9; 5.1; 5.0; ...
(600, 530); 6.7; 6.7; 7.2; ...';
Method #1 (values without semi-colons stored in array):
foreach(explode("\r\n",$document) as $row){ // split the content by return then newline
$result[]=explode("; ",$row); // split each row by semi-colon then space
}
var_export($result);
/* Output:
[
['(400, 530)','6.9','5.7','5.0','...'],
['(500, 530)','7.9','5.1','5.0','...'],
['(600, 530)','6.7','6.7','7.2','...']
]
) */
Method #2 (values with semi-colons stored in array):
foreach(explode("\r\n",$document) as $row){ // split the content by return then newline
$result[]=preg_split('/(?<!,) /',$row); // split each row by space not preceeded by comma
}
var_export($result);
/* Output:
[
['(400, 530);','6.9;','5.7;','5.0;','...'],
['(500, 530);','7.9;','5.1;','5.0;','...'],
['(600, 530);','6.7;','6.7;','7.2;','...']
]
) */
Here is demo of both methods.
Keep in mind I am only focusing on the string splitting inside the loop. Kris' advice on file handling is advisable.
Depending on your environment, you may need to adjust the first explode by removing \r
or similar.