Say I have the following string:
开发者_JAVA百科$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
explode
does not do Regexen.
preg_split
does.
You should use preg_split instead of explode
精彩评论