开发者

What's up with PHP explode() patterns?

开发者 https://www.devze.com 2023-03-20 19:14 出处:网络
Say I have the following string:开发者_JAVA百科 $str = \"Hello, my name is Bob and I like \'pizza\'. Do you like pizza??\"

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

精彩评论

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