开发者

What's up with PHP explode() patterns?

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜