Say I have the following string:
$str = "Hello, my name is Bob and I like 'pizza'. Do you like pizza??"
Currently I am able to split/explode this string on the whitespace using:
$arr = explode(' ', $str);
but I want to use the regex pattern \W like so:
$arr = explode('\W', $str);
This should separate all words that aren’t punctuation, allowing the 'pizza' part to be separated as pizza. Except it returns nothing (I get an empty array back).
What can I do?
Use preg_split:
http://www.php.net/manual/en/function.preg-split.php