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.

2
  • Use preg_replace to remove the special characters. See stackoverflow.com/questions/657643/… Commented Sep 5, 2013 at 8:41
  • Where is this HTML code coming from? There is no reason for the database layer to escape HTML special characters. Commented Sep 5, 2013 at 8:50

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.