Home  >  Article  >  Backend Development  >  PHP remove html tag function - strip_tags and htmlspecialchars

PHP remove html tag function - strip_tags and htmlspecialchars

伊谢尔伦
伊谢尔伦Original
2016-11-26 14:12:595609browse

1、strip_tags

功能:去掉 HTML 及 PHP 的标记。

语法: string strip_tags(string str);

返回值: 字符串

说明:本函式可去掉字符串中包含的任何HTML及 PHP 的标签。若是字符串的 HTML 及 PHP 标签原来就有错,例如少了大于的符号,则也会传回错误。

注意:遇到提炼文字内容是,会出现 这样的空格是无法通过上面的行数替换掉,这个时候需要单独使用str_replace进行特定替换

2、htmlspecialchars

功能:将特殊字元转成 HTML 格式。

语法: string htmlspecialchars(string string);

返回值: 字符串

本函式将特殊字元转成 HTML 的字串格式 ( &....; )。最常用到的场合可能就是处理客户留言的留言版了。

& (和) 转成 & 
" (双引号) 转成 " 
< (小于) 转成 < 
> (大于) 转成 >

此函数只转换上面的特殊字元,并不会全部转换成 HTML 所定的 ASCII 转换。


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