在网页程序开发中,htmlspecialchars、strip_tags、addslashes函数是最常见的,本篇文章将会分别来介绍这三个函数。 1.strip_tags()函数 strip_tags() 函数去除字符串中的 HTML、XML 以及 PHP 的标签。 示例 <?php $name="Hello <b>world!</b>"; $tags=strip_tags($name); echo $tags; ?> 2.htmlspecialchars()函数 htmlspecialchars() 函数把预定义的字符转换为 HTML 实体。 具体来说本函数会转化以下字符:
示例 <?php $str = "This is some <b>bold</b> text."; echo htmlspecialchars($str); ?> 3.htmlentities()函数 或许你还在遗憾htmlspecialchars只能处理4个html标记,那么现在你不要遗憾了,htmlentities是转化全部字符。不可谓不强大 示例 <?php $str = "<? PHP?h????>"; echo htmlentities($str); ?> 4.函数stripslashes与addslashes本是一对,addslashes是使用反斜线引用字符串,stripslashes是还原addslashes引用的字符串。 该函数一般都是数据库查询之前就需要处理的必要步骤,该字符串为了数据库查询语句等的需要在某些字符前加上了反斜线。这些字符是单引号(')、双引号(")、反斜线(/)与 NUL(NULL 字符)。 【相关文章推荐】 php 去除字符串标签strip_tags() 函数示例详解 php addslashes()函数和stripslashes()函数实例详解 php htmlspecialchars()和strip_tags函数的区别 以上就是php中htmlspecialchars、strip_tags、addslashes函数的简单介绍的详细内容,更多请关注php中文网其它相关文章! 文章来源:https://www./faq/364143.html |
|