Skip to content

Instantly share code, notes, and snippets.

@otkrsk
Last active August 10, 2016 04:29
Show Gist options
  • Save otkrsk/88db28e0ea4975ec421b2bf9056dd1cd to your computer and use it in GitHub Desktop.
Save otkrsk/88db28e0ea4975ec421b2bf9056dd1cd to your computer and use it in GitHub Desktop.
Preserve HTML tags and formatting into a MySQL database.
$str = "I 'am' a <strong>monster</strong>!";
// This will preserve the HTML tags (as well as the quotes) and make it safe to save into MySQL.
echo htmlentities($str, ENT_QUOTES);
// To display it with all its HTML glory, use html_entity_decode().
echo html_entity_decode($str);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment