Home>Article>Backend Development> Introduction to the method of PHP outputting HTML code as it is on the page
This article will introduce to you how PHP outputs HTML code as it is on the page. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to everyone.
#The conversion between strings and HTML is mainly done using the htmlentities() function.
php中文网"; echo $str; echo "
"; echo htmlentities($str,ENT_QUOTES,"UTF-8"); ?>
The running result is:
Tips: When applying this function to convert a string into an HTML string During the process, set the character set of the parameter charset to utf-8 to avoid garbled characters when outputting Chinese characters.
htmlentities() function converts characters into HTML entities.
Tip: To convert HTML entities back to characters, use the html_entity_decode() function.
Tip: Please use the get_html_translation_table() function to return the translation table used by htmlentities().
Recommended:PHP video tutorial
The above is the detailed content of Introduction to the method of PHP outputting HTML code as it is on the page. For more information, please follow other related articles on the PHP Chinese website!