html_entity_decode无法正常工作

时间:2018-01-20 17:44:24

标签: php regex preg-replace html-entities

我正在使用html_entity_decode来解码html代码,然后使用preg_replace,但由于某种原因它出于某种原因正在替换我的所有单引号。我做错了什么?

<?php

$userResponse = "I&#039;m tired.";
$userResponse = html_entity_decode($userResponse); //make codes like &#039; into '
$userResponse = preg_replace("~[^*a-zA-Z,.!?' ]~", "", $userResponse);
echo $userResponse;

?>

结果:我很累。

预期结果:我累了。

1 个答案:

答案 0 :(得分:-1)

$userResponse = "I&#039;m tired.";
echo $userResponse = html_entity_decode($userResponse);

仅编写此代码。