str_replace和htmlspecialchars不起作用

问题描述

好的,我知道我看到的不一定是代码中所说的。我把那部分弄清楚了。但是我有一长串的字符,需要将它们作为html实体而不是标点符号存储在数据库中。我已将代码更新为:

$searchval = array("á","–","—","/"," ","-","...","…","\&","\'","í","\[","\~","\"","\]");
  $replaceval = array("\&egrave\;","\&ndash\;","\&mdash\;","\&#47","\&#nbsp\;","\&#hyphen\;","\&hellip\;","\&amp\;","\&apos\;","\&igrave\;","\&lbrack\;","\&ntilde\;","\&quot\;","\&rbrack\;");
  str_replace($searchval,$replaceval,$fixed);

但是实体名称并没有进入数据库

You have an error in your sql Syntax; check the manual that corresponds to your MysqL server version for the right Syntax to use near 'most # rig&ht...'

如何让实体进入数据库而不是标点符号

<!DOCTYPE html>
<html>
<body style="margin-left:50px">

<?PHP

     $fixed = "this is al'most right";
     echo $fixed;
     echo "<br>";
     echo "htmlspecialchars: ";
     echo htmlspecialchars($fixed,ENT_QUOTES);
     echo "<br>";
     echo "str_replace: ";
     echo str_replace("'","&apos;",$fixed);
     echo "<br>";


?>

</body>
</html>

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)