mihir
mihir

Reputation: 1

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?

Upvotes: 0

Views: 54

Answers (2)

Ryan
Ryan

Reputation: 14649

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.

Upvotes: 0

Sulthan Allaudeen
Sulthan Allaudeen

Reputation: 11310

htmlspecialchars will help you out.

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

Upvotes: 1

Related Questions