Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve code from database with php ?

Tags:

php

mysql

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?

like image 814
shanto Avatar asked Jan 25 '26 21:01

shanto


2 Answers

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();

like image 133
StaticVariable Avatar answered Jan 27 '26 09:01

StaticVariable


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.

like image 28
Rick Kuipers Avatar answered Jan 27 '26 09:01

Rick Kuipers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!