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)].
#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 & 'Adams'"; 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 & 'Adams' John & 'Adams' John & 'Adams'
If you view the source code in a browser, you will see these HTML:
<html> <body> John & 'Adams'<br /> John & 'Adams'<br /> John & 'Adams' </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!