zoukankan      html  css  js  c++  java
  • strip_tags、htmlentities、htmlspecialchars的区别

    一、strip_tags() 函数剥去字符串中的 HTML、XML 以及 PHP 的标签。

    strip_tags(string,allow)

    注释:可通过allow设置允许的标签。这些标签不会被删除。

    注释:该函数始终会剥离 HTML 注释。这点无法通过 allow 参数改变。

    注释:该函数是二进制安全的。

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

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

    预定义的字符包括   &  "  '  <  > 

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

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

    与htmlspecialchars最大的不同是: 会转换所有具有 HTML 实体的字符。

    总结: 

    strip_tags去除字符串中的HTML、XML、PHP标签,

    htmlentities转换所有HTML标签,

    htmlspecialchars只转换 & 、’、 “、 <、> 这五个特殊符号,

    在使用htmlentities不指定编码时中文会乱码 。

  • 相关阅读:
    C#与C++与互操作
    WPF GridView动态添加项并读取数据
    C#使用消息队列(MSMQ)
    使用代码浏览WPF控件模版
    PowerShell将运行结果保存为文件
    opencv + ffmpeg
    vmware
    HttpComponents Downloads
    pytorch 安装
    opencv 3.4.0 的编译
  • 原文地址:https://www.cnblogs.com/splendid/p/10540742.html
Copyright © 2011-2022 走看看