[英]PHP Double Quotes from MySQL, breaking htmlentities
我在这里的结果有疑问。 请有人告诉我我做错了。
我在mysql字段中有此文本:
----------------------------------------------------
text “strange double quotes” "normal double quotes"
----------------------------------------------------
在文本区域内,我在数据库中回显字符串
<textarea>
$string = stripslashes(htmlspecialchars_decode($string,ENT_QUOTES));
echo htmlspecialchars($string);
</textarea>
并崩溃(不显示任何内容)。
但是如果我只有普通文字或普通引号:
"this is a correct text with quotes"
这可行。
你知道我需要做什么吗?
TY
您拥有的代码按预期工作:
<?php
$string = 'text “strange double quotes” "normal double quotes"';
$string = stripslashes(htmlspecialchars_decode($string,ENT_QUOTES));
echo htmlspecialchars($string);
?>
产量:
text “strange double quotes” "normal double quotes"
在将$string
的值传递到htmlspecialchars_decode
之前,检查它的值,例如:
<?php
$string = null;
$string = stripslashes(htmlspecialchars_decode($string,ENT_QUOTES));
echo htmlspecialchars($string);
?>
根据您的错误描述,不产生/空/空白。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.