Home  >  Article  >  Backend Development  >  How to convert string to html in php

How to convert string to html in php

王林
王林Original
2020-08-15 15:45:373504browse

php method to convert string to html: You can use the htmlentities() function to achieve this. This function can convert characters into HTML entities. Function syntax: [htmlentities(string,quotestyle,character-set)].

How to convert string to html in php

#htmlentities() function converts characters into HTML entities.

(Recommended tutorial: php graphic tutorial)

Syntax:

htmlentities(string,quotestyle,character-set)

Implementation code:

<html>
<body>
<?php
$str = "John & &#39;Adams&#39;";
echo htmlentities($str, ENT_COMPAT);
echo "<br />";
echo htmlentities($str, ENT_QUOTES);
echo "<br />";
echo htmlentities($str, ENT_NOQUOTES);
?>
</body>
</html>

( Video tutorial recommendation: php video tutorial)

Output:

John & &#39;Adams&#39;
John & &#39;Adams&#39;
John & &#39;Adams&#39;

If you view the source code in a browser, you will see these HTML:

<html>
<body>
John &amp; &#39;Adams&#39;<br />
John &amp; &#039;Adams&#039;<br />
John &amp; &#39;Adams&#39;
</body>
</html>

The above is the detailed content of How to convert string to html in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn