簡體   English   中英

我如何在php mysql的html內容中使用特殊字符

[英]how i used special characters in html content in php mysql

<p>This is Jhone's home.</p>

這不在我的前台顯示。

當我使用<p>This is Jhone\\'s home.</p>顯示。

我需要不加反斜杠。 我能怎么做?

htmlspecialchars將幫助您。

<?php
$str = "<p>This is Jhone's home.</p>";
echo htmlspecialchars($str);
?>

使用ENT_QUOTES作為htmlspecialchars的第二個參數將轉換引號。 同樣,提供正確的字符集也非常重要。

echo htmlspecialchars("This is Jhone's home.", ENT_QUOTES', 'UTF-8');

執行的翻譯是:

'&' (ampersand) becomes '&amp;'
'"' (double quote) becomes '&quot;' when ENT_NOQUOTES is not set.
"'" (single quote) becomes '&#039;' (or &apos;) only when ENT_QUOTES is set.
'<' (less than) becomes '&lt;'
'>' (greater than) becomes '&gt;'

因此,如果您在瀏覽器上查看源,則輸出將是這樣的:

This is Jhone&quot;s home.

暫無
暫無

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

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