[英]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.