Home  >  Article  >  Backend Development  >  PHP functions: htmlspecialchars(), htmlentities(), etc._PHP tutorial

PHP functions: htmlspecialchars(), htmlentities(), etc._PHP tutorial

WBOY
WBOYOriginal
2016-07-14 10:11:47751browse

 


在web编辑器往数据库写文章内容,或读取数据库内容时,经常会出现不解析的问题,出现一大堆代码,这其实是html实体和相应的字符串转换的问题。

主要涉及到htmlspecialchars(),htmlentities()、htmlspecialchars_decode() 这几个函数。


htmlspecialchars() 函数把一些预定义的字符转换为 HTML 实体。

预定义的字符是:

& (和号) 成为 &

" (双引号) 成为 "

' (单引号) 成为 '

< (小于) 成为 <

> (大于) 成为 >

 

 

PHP htmlentities() 函数

定义和用法

htmlentities() 函数把字符转换为 HTML 实体。

语法

htmlentities(string,quotestyle,character-set)

这里要注意这二者的区别

 

 

PHP htmlspecialchars_decode() 函数

定义和用法

htmlspecialchars_decode() 函数把一些预定义的 HTML 实体转换为字符。

会被解码的 HTML 实体是:

& 成为 & (和号)

" 成为 " (双引号)

' 成为 ' (单引号)

< 成为 < (小于)

> 成为 > (大于)

 

 

 

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/477296.htmlTechArticle在web编辑器往数据库写文章内容,或读取数据库内容时,经常会出现不解析的问题,出现一大堆代码,这其实是html实体和相应的字符串转换...
Statement:
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