如何用php从数据库中检索代码?

时间:2021-12-02 15:14:46

I want to store HTML code in mysql database. If I want to store the following code into database

我想在mysql数据库中存储HTML代码。如果我想将以下代码存储到数据库中

<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?

他们就像他们一样。但是当我检索它们并使用php进行回显时,标记就消失了。但是我想要像上面那样回应他们。我还希望不仅存储和显示HTML,还显示其他代码(c、java、php)。有人知道吗?

2 个解决方案

#1


2  

you can use htmlentities () php function to echo html codes

您可以使用htmlentities () php函数来回显html代码

    $str = "
<html> 
 <body>
     <p> this is a paragraph </p
 </body>
</html>
";


echo htmlentities($str);

You can also use htmlspecialchars();

还可以使用htmlspecialchars();

#2


1  

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.

您可以使用htmlentities($str),另一个值得使用的是

将这些标记放在代码周围将保留换行符、制表符和空格。如果你想展示它。 

#1


2  

you can use htmlentities () php function to echo html codes

您可以使用htmlentities () php函数来回显html代码

    $str = "
<html> 
 <body>
     <p> this is a paragraph </p
 </body>
</html>
";


echo htmlentities($str);

You can also use htmlspecialchars();

还可以使用htmlspecialchars();

#2


1  

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.

您可以使用htmlentities($str),另一个值得使用的是

将这些标记放在代码周围将保留换行符、制表符和空格。如果你想展示它。