PHP explosion()处理特殊字符时不能正常工作


php explode() not working properly with special characters

$this->row['contents'] = strip_tags($this->row['contents']);
$this->words = explode(" ", $this->row['contents']);

上面的代码应该为$this->row['contents']的每个单词创建一个具有key => value对的数组。在正常情况下,它工作得很好,但是对于像:

这样的字符串

每升10.40美元。

分隔成

[0] => This
[1] => Costs U$
[2] => 10.40 per
[3] => liter.

有什么办法解决这个问题吗?

也许这段代码对你有帮助

$this->words = preg_split('/'s+/', $this->row['contents']);