簡體   English   中英

MySQL的PHP​​雙引號打破了htmlentities

[英]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” &quot;normal double quotes&quot;

在將$string的值傳遞到htmlspecialchars_decode之前,檢查它的值,例如:

<?php
$string = null;

$string = stripslashes(htmlspecialchars_decode($string,ENT_QUOTES));
echo htmlspecialchars($string);
?>

根據您的錯誤描述,不產生/空/空白。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM