I want to store HTML code in mysql database. If I want to store the following code into database
<html>
<body>
<p> this is a paragraph </p
</body>
</html>
they store as they are. But when I retrieve them and echo with php the tag get vanished. But I want to echo them as they are above. I also want to store and show not only HTML but other code (c,java,php) also. Anyone have any idea?
you can use htmlentities () php function to echo html codes
$str = "
<html>
<body>
<p> this is a paragraph </p
</body>
</html>
";
echo htmlentities($str);
You can also use htmlspecialchars();
You can use htmlentities($str) for that, another nice thing to use is <pre></pre>
Putting those tags around the code will preserve newlines, tabs and spaces. In case you want to showcase it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With