我目前使用以下方法将从数据库输出的utf8mb4_unicode_ci文本拆分为@、#、$和空格:
$textSplit = preg_split("/(?=[ @#$])/", $text, -1, PREG_SPLIT_NO_EMPTY);但是,当我用撇号拆分一段数据库文本时,我得到了以下输出:
// $text is a database value that equals "Is this John's text?"
$textSplit = preg_split("/(?=[ @#$])/", $text, -1, PREG_SPLIT_NO_EMPTY);
// Outputs array(5) { [0]=> string(2) "Is" [1]=> string(5) " this" [2]=> string(5) " John&" [3]=> string(6) "#039;s" [4]=> string(5) " text" }
var_dump($textSplit);有没有什么办法可以防止preg_split把撇号当作html实体来处理,从而像这样拆分文本?
array(4) { [0]=> string(2) "Is" [1]=> string(5) " this" [2]=> string(7) " John's" [3]=> string(5) " text" }发布于 2015-04-17 11:33:26
如果有人遇到同样的问题,我可以使用htmlspecialchars_decode($text,ENT_QUOTES)来解决。感谢每个人在这个解决方案中的帮助!
发布于 2015-04-17 11:30:58
试着向后看:
/(?<!&)(?=[ @#$])/它不会匹配&后面的任何字符,从而阻止&#xxx匹配。
https://stackoverflow.com/questions/29689534
复制相似问题