I need to generate an array with preg_split
, as implode('', $array)
can re-generate the original string. `preg_split of
$str = 'this is a test "some quotations is her" and more';
$array = preg_split('/( |".*?")/', $str, -1, PREG_SPLIT_DELIM_CAPTURE);
generates an array of
Array
(
[0] => this
[1] =>
[2] => is
[3] =>
[4] => a
[5] =>
[6] => test
[7] =>
[8] =>
[9] => "some quotations is here"
[10] =>
[11] =>
[12] => and
[13] =>
[14] => more
)
I need to take care of the space before/after the quotation marks too, to generate an array with the exact pattern of the original string.
For example, if the string is test "some quotations is here"and
, the array should be
Array
(
[0] => test
[1] =>
[2] => "some quotations is here"
[3] => and
)
Note: The edit has been made based on initial discussion with @mikel.