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($str, ENT_QUOTES);// Outputs: A 'quote' is <b>bold</b>
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>
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($str, ENT_QUOTES);// Outputs: A 'quote' is <b>bold</b>
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