Home > php教程 > PHP开发 > body text

Definition and usage of php htmlentities() function

高洛峰
Release: 2017-01-03 14:12:50
Original
1216 people have browsed it

php htmlentities() function converts characters into HTML entities. This article introduces the basic usage and examples of the php htmlentities() function to coders. Coders in need can refer to it.

Definition and usage

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().

Syntax

htmlentities(string,flags,character-set,double_encode)

php htmlentities()函数的定义和用法

##Technical details

php htmlentities()函数的定义和用法

Example 1

Convert characters to HTML entities:

";
echo htmlentities($str, ENT_QUOTES); // 转换双引号和单引号
echo "
"; echo htmlentities($str, ENT_NOQUOTES); // 不转换任何引号 ?>
Copy after login

The HTML output of the above code is as follows (view Source code):




Bill & 'Steve'
Bill & 'Tarzan'
Bill & 'Steve'
Copy after login

Browser output of the above code:

Bill & 'Steve'
Bill & 'Steve'
Bill & 'Steve'
Copy after login

Example 2

Convert some characters to HTML entities by using Western European character sets:

Copy after login

The HTML output of the above code is as follows (view source code ):




My name is Øyvind Åsane. I'm Norwegian.

Copy after login

Browser output of the above code:

My name is ?yvind ?sane. I'm Norwegian.


The definition and usage of the php htmlentities() function above are all the content shared by the editor. I hope it can give you a reference, and I hope you will support the PHP Chinese website.

For more articles related to the definition and usage of the php htmlentities() function, please pay attention to 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!