Heim  >  Artikel  >  Backend-Entwicklung  >  php 去除多余的HTML标签

php 去除多余的HTML标签

WBOY
WBOYOriginal
2016-07-25 08:56:341096Durchsuche
  1. echo strip_tags($str);
复制代码

2,只保留

一个标签的话,只需要将

字符串写到strip_tags的第二个参数中。

  1. echo strip_tags($str, "

    ");

复制代码

3,要保留

…多个标签,只需要将多个标签用空格分隔后写到strip_tags的第二个参数中。

  1. echo strip_tags($str, "

    ");

复制代码

4,保留所有标签,仅仅转义用addslashes(), stripslashes(), htmlspecialchars(), htmlentities(), nl2br() 等函数.

addslashes(), stripslashes() 一般是入数据库和出库的时候使用,以免变量中存储类似引号这些关键词,这样的话,本来是内容的部分却被数据库识别为标识符来执行,就会引起错误.

htmlspecialchars() 函数只用来转义少量HTML, &,双引号,大于号和小于号.并不会全部转换成 HTML 所定的 ASCII 转换

htmlentities() 本函数有点像 htmlspecialchars() 函数,但本函数会将所有 string 的字符都转成 HTML 的特殊字集字符串。 不过在转换后,阅读网页源代码时,尤其是网页源代码的中文字,在浏览时会显示不正常,这点要注意下。 您可能感兴趣的文章: php去除html标签的二种方法 php过滤html标记的函数strip_tags用法举例(图文) php删除html标签的三种方法分享 php删除html标签及字符串中html标签的代码 php 去除html标记之strip_tags与htmlspecialchars的区别分析 php删除字符串中html标签的函数 去掉内容中 html 标签的代码 提取html标签的php代码 php正则过滤html标签、空格、换行符等的代码示例 php去除html标签获得输入纯文本文档strip_tags php使HTML标签自动补全闭合函数的代码 php实现html标签自动补全的代码 thinkPHP的Html模板标签的使用方法



Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn