0

when I save html code with php in the database, the html code looks like:

& lt ; b & gt ; (for <b>)

I know they are special characters. When I want to display it with echo, I have to decode it with:

html_entity_decode($test);

How can I save the html without specials chars so that I wouldn't need the html_entity_decode?

Thank you.

vvns
  • 3,548
  • 3
  • 41
  • 57
labu77
  • 605
  • 1
  • 9
  • 30
  • Use preg_replace to remove the special characters. See http://stackoverflow.com/questions/657643/how-to-remove-html-special-chars – Steven Liao Sep 05 '13 at 08:41
  • Where is this HTML code coming from? There is no reason for the database layer to escape HTML special characters. – Brenton Alker Sep 05 '13 at 08:50

1 Answers1

1

when I save html code with php in the database....

No you seem to be saving HTML encoded HTML code. So given some HTML code you are currently encoding it as html (htmlspecialchars()), encoding it for insert (via mysql[i]_real_escape_string() or parameter binding) into the database and de-encoding it on retrieval - just skip the extra encoding.

symcbean
  • 47,736
  • 6
  • 59
  • 94