I'm using regex in preg_split to split a string into separate parts.
$string = 'text required name="first_name" label="First Name" column="1/2"';
$ps = preg_split("/\s(?![\w\s]+\")/u", $string);
echo '<pre>',print_r($ps,1),'</pre>';
The above code gives the following result and is working correctly:
Array
(
[0] => text
[1] => required
[2] => name="first_name"
[3] => label="First Name"
[4] => column="1/2"
)
But if I add any special characters inside the double quotemarks the string is broken down into separate array items:
$string = 'text required name="first_name" label="First Name! $ , ." column="1/2"';
$ps = preg_split("/\s(?![\w\s]+\")/u", $string);
echo '<pre>',print_r($ps,1),'</pre>';
Resulting in:
Array
(
[0] => text
[1] => required
[2] => name="first_name"
[3] => label="First
[4] => Name!
[5] => $
[6] => ,
[7] => ."
[8] => column="1/2"
)
How can I keep "First Name! $ , ." in the same array item?
e.g. like this:
Array
(
[0] => text
[1] => required
[2] => name="first_name"
[3] => label="First Name! $ , ."
[4] => column="1/2"
)