php 去除html标记--strip_tags与htmlspecialchars的区别详解_php技巧

WBOY
Release: 2016-05-17 08:58:35
Original
1075 people have browsed it
strip_tags
  去掉 HTML 及 PHP 的标记。
  语法: string strip_tags(string str);
  传回值: 字串
  函式种类: 资料处理
  内容说明
  本函式可去掉字串中包含的任何 HTML 及 PHP 的标记字串。若是字串的 HTML 及 PHP 标签原来就有错,例如少了大于的符号,则也会传回错误。而本函式和 fgetss() 有着相同的功能。
 
htmlspecialchars
  将特殊字元转成 HTML 格式。
  语法: string htmlspecialchars(string string);
  传回值: 字串
  函式种类: 资料处理
  本函式将特殊字元转成 HTML 的字串格式 ( &....; )。最常用到的场合可能就是处理客户留言的留言版了。
  & (和) 转成 &
  " (双引号) 转成 "
    > (大于) 转成 >
  '' (单引号) 转成 '
  此函式只转换上面的特殊字元,并不会全部转换成 HTML 所定的 ASCII 转换。
复制代码 代码如下:

     $new  = htmlspecialchars( "Test" , ENT_QUOTES); 
     echo   $new ;  
?>

结果: Test
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!