shanto
shanto

Reputation: 47

How to retrieve code from database with php ?

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?

Upvotes: 3

Views: 759

Answers (2)

Rick Kuipers
Rick Kuipers

Reputation: 6617

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.

Upvotes: 1

StaticVariable
StaticVariable

Reputation: 5283

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

Upvotes: 2

Related Questions