Skip to content
Advertisement

How to Save HTML to mysql using PHP?

I am trying to post some html though a form to a php page and then trying to save that html into database the problem which I am facing is that when I save this to database it includes many html entities with it

for example my original html code is

JavaScript

But When I save it db it becomes

JavaScript

what should I do to save the html as it is and echo it any time it is needed as a html code

here is my PHP code

JavaScript

Advertisement

Answer

You could use htmlspecialchars and htmlspecialchars_decode combined with htmlEntities ,html_entity_decode

htmlspecialchars — Convert special characters to HTML entities

See documentation here http://php.net/htmlspecialchars

htmlspecialchars_decode — Convert special HTML entities back to characters
See documentation here http://php.net/manual/en/function.htmlspecialchars-decode.php

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement