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:
但我想使用regex模式如下:
$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?
我能做什么?
Thanks
谢谢
3 个解决方案
#1
14
Use preg_split:
使用preg_split:
http://www.php.net/manual/en/function.preg-split.php
http://www.php.net/manual/en/function.preg-split.php
#1
14
Use preg_split:
使用preg_split:
http://www.php.net/manual/en/function.preg-split.php
http://www.php.net/manual/en/function.preg-split.php