I have this string:
$string = "My name is Emma and i have a dillemma, what's the distance between 'New York' and 'Athene' ?";
I'm splitting this string by space and some operators(=,<,>,!=,>=,<=,<>) using this code:
$split = preg_split('/\s+|(,|[<>!]?=|<>?|>)/', $string, null, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
For now the result of this splitting is this array:
Array
(
[0] => My
[1] => name
[2] => is
[3] => Emma
[4] => and
[5] => i
[6] => have
[7] => a
[8] => dillemma
[9] => ,
[10] => what's
[11] => the
[12] => distance
[13] => between
[14] => 'New
[15] => York'
[16] => and
[17] => 'Athene'
[18] => ?
)
Now the only problem that i have is that i want the white spaces between '' to not be splitted but to remove '' after split, in this example above you can see 'New York' is splitted into:
[14] => 'New
[15] => York'
My desired outcome is:
[14] => New York
And also 'Athene', i want it to be:
[16] => Athene
So basicly the above array should look like this:
Array
(
[0] => My
[1] => name
[2] => is
[3] => Emma
[4] => and
[5] => i
[6] => have
[7] => a
[8] => dillemma
[9] => ,
[10] => what's
[11] => the
[12] => distance
[13] => between
[14] => New York
[15] => and
[16] => Athena
[17] => ?
)
And yes the distance between those two cities is 4,925 miles or 7925 kilometers :D
Thank you! :D