Home >Backend Development >PHP Tutorial >Introduction to the method of PHP outputting HTML code as it is on the page

Introduction to the method of PHP outputting HTML code as it is on the page

青灯夜游
青灯夜游forward
2020-03-31 16:33:074091browse

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.

Introduction to the method of PHP outputting HTML code as it is on the page

#The conversion between strings and HTML is mainly done using the htmlentities() function.

Introduction to the method of PHP outputting HTML code as it is on the page

<?php
header("Content-Type: text/html; charset=utf-8");
$str="<a href=\"www.php.cn\">php中文网</a>";
echo $str;
echo "<br>";
echo htmlentities($str,ENT_QUOTES,"UTF-8");

?>

The running result is:

Introduction to the method of PHP outputting HTML code as it is on the page

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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete