How to convert string to html in php

王林
Release: 2023-03-04 14:52:01
Original
3567 people have browsed it

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)
Copy after login

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>
Copy after login

( Video tutorial recommendation: php video tutorial)

Output:

John & &#39;Adams&#39;
John & &#39;Adams&#39;
John & &#39;Adams&#39;
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template