Friday, April 21, 2017

Best way to store HTML code in MYSQL and echo from mysql PHP

Best way to store HTML code in MYSQL database and echo/display from mysql database to browser using PHP.

htmlentities(HTML, ENT_QUOTES, "UTF-8") function — Convert all applicable characters to HTML entities.

This function Returns the encoded string. If the input string contains an invalid code unit sequence within the given encoding an empty string will be returned, unless either the ENT_IGNORE or ENT_SUBSTITUTE flags are set.

$str "A 'quote' is <b>bold</b>";

echo $str = htmlentities($strENT_QUOTES);// Outputs: A &#039;quote&#039; is &lt;b&gt;bold&lt;/b&gt;

If you want to decode instead (the reverse) you can use html_entity_decode().

echo html_entity_decode($str);
// A 'quote' is <b>bold</b>

No comments:

Post a Comment

Total Pageviews