I am trying to split the line have space and text enclosed.. I am not getting proper output
$line = '"name" "Brand" "EAN" "shipping" "Combinable"';
$lineArray = preg_split('/^\"\s+\"/', $line);
print_r($lineArray);
I am trying to split the line have space and text enclosed.. I am not getting proper output
$line = '"name" "Brand" "EAN" "shipping" "Combinable"';
$lineArray = preg_split('/^\"\s+\"/', $line);
print_r($lineArray);
You don't need to escape the quotes, and your split is incorrect anchored at the beginning of the string. Try this:
$line = '"name" "Brand" "EAN" "shipping" "Combinable"';
$lineArray = preg_split('/"\s+"/', $line);
Note that this causes the first element to start with a quote, and the last element to end with a quote. To keep the quotes, use assertions:
$lineArray = preg_split('/(?<=")\s+(?=")/', $line);
This produces a $lineArray
like (note how it kept the quotes):
Array ( [0] => "name" [1] => "Brand" [2] => "EAN" [3] => "shipping" [4] => "Combinable" )