Php Pre_split将撇号视为html实体

Php Pre_split将撇号视为html实体,php,html,regex,Php,Html,Regex,我目前正在使用以下方法将从数据库中输出的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("/(?

我目前正在使用以下方法将从数据库中输出的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" }
试着回头看看:

/(?<!&)(?=[ @#$])/
/(?

它不会匹配以下任何字符&,阻止
&#xxx
匹配。

如果有人遇到同样的问题,我可以使用htmlspecialchars_decode($text,ENT#u引号)解决它。感谢大家帮助我找到这个解决方案!

虽然我不知道如何阻止preg_split的这种行为,但这很容易通过查找解决。你能提供一个
$text
的例子吗?@Docteur你能用一些你认为可以解决这个问题的示例代码来回答这个问题吗?我可以试试吗我会将你的答案标记为正确。看起来你在存储字符串之前在字符串上使用了
htmlentities
,请尝试类似
$textplit=preg\u split(“/(?=[@#$])/”,html\u entity\u decode($text),-1,preg\u split\u NO\u EMPTY);
@hwnd当然,我的第二个代码段中的第一条注释指定了$text的值。它是数据库中的一个变量,值为“这是John的文本吗?”通过将代码封装在严重的(`)字符中来内联格式化代码,就像这样
`htmlspecialchars\u decode($text,entu QUOTES)`