Summary of PHP special character conversion entity functions
data-id="1190000005008217" data-license="sa">
1.htmlspecialchars($string, $flag)
(Convert special characters to HTML entities 转换特殊字符为HTML实体)
<code>预定义的字符是: & (和号)成为 & " (双引号)成为 " ' (单引号)成为 ' < (小于)成为 < > (大于)成为 > </code>
$flag 默认为ENT_COMPAT | ENT_HTML401
常量名 | 描述 |
---|---|
ENT_COMPAT | 转换双引号,不转换单引号。 |
ENT_QUOTES | 单引号和双引号都转换。 |
ENT_NOQUOTES | 单引号和双引号都不转换。 |
ENT_HTML401 | 作为HTML 4.01编码处理。 |
ENT_XML1 | 作为XML 1编码处理。 |
ENT_XHTML | 作为XHTML编码处理。 |
ENT_HTML5 | 作为HTML 5编码处理。 |
EXP:
<code> $str = '"2015竞赛&"'; echo htmlspecialchars($str); //"2015竞赛&"quot;</code>
2.htmlspecialchars_decode($string, $flag)
(与上面相反,将特殊的 HTML 实体转换回普通字符)
EXP
<code> $str = "<p>this -> "</p>\n" ; echo htmlspecial_decode($str); // this -> " /*不转换双引号*/ echo htmlspecial_decode($str, ENT_NOQUOTES); // this -> "</code>
3. htmlentities
<code>`htmlentities($string, $flag)` 这个函数与htmlspecialchars的区别网上教程说是也会转换中文,但是我本地php5.5测试两个效果一样</code>
<code> $str='<a href="test.html">测试页面</a>'; echo htmlentities($str); $str='<a href="test.html">测试页面</a>'; echo htmlspecialchars($str);</code>
4. html_entity_decode
<code>是`htmlentities`的反函数 </code>
5.nl2br
<code>转换换行符(\n(unix), \r(Mac), \r\n(Win))为`<br>`</code>
以上就介绍了PHP特殊字符转换实体函数汇总,包括了特殊字符,php方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Guide to Table Border in HTML. Here we discuss multiple ways for defining table-border with examples of the Table Border in HTML.

This is a guide to Nested Table in HTML. Here we discuss how to create a table within the table along with the respective examples.

Guide to HTML margin-left. Here we discuss a brief overview on HTML margin-left and its Examples along with its Code Implementation.

Guide to HTML Table Layout. Here we discuss the Values of HTML Table Layout along with the examples and outputs n detail.

Guide to HTML Input Placeholder. Here we discuss the Examples of HTML Input Placeholder along with the codes and outputs.

Guide to the HTML Ordered List. Here we also discuss introduction of HTML Ordered list and types along with their example respectively

Guide to Moving Text in HTML. Here we discuss an introduction, how marquee tag work with syntax and examples to implement.

Guide to HTML onclick Button. Here we discuss their introduction, working, examples and onclick Event in various events respectively.
