简体   繁体   中英

how i used special characters in html content in php mysql

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

This is not display in my front site. but

When I use <p>This is Jhone\\'s home.</p> It display.

I need to put without backslash. How can I do?

htmlspecialchars will help you out.

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

Using ENT_QUOTES as the second argument to htmlspecialchars will convert the quotations marks. Also, it is extremely important to provide the correct charset.

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

The translations that are performed are:

'&' (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;'

So if you view the source on the browser, your output will be this:

This is Jhone&quot;s home.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM