Error using explod : Parse error: syntax error, unexpected '$lines' (T_VARIABLE)
I want to extract content of a text file (3 lines) in an array, then explode this array by "," delimiter, then explode each value by ":" delimiter.
For the first line it works, not for the second... Don't know why.
Content of the file:
1:a,2:b,3:c
10:a,5:b,4:c
8:c,9:a,3:b
$lines = file('test.txt');
$top_table = explode(",", $lines[0]);
foreach ($top_table as $key => $str)
{
$top_table[$key] = explode(":", $str);
}
$top_splits = explode("," $lines[1]);
foreach ($top_splits as $key => $str)
{
$top_splits[$key] = explode(":", $str);
}
This line : $top_splits = explode("," $lines[1]); is throwing the error. If I print $lines[1], it works so I don't know why first explode on $lines[0] then first foreach work well, but not the second one.