Jquery中文网 www.jquerycn.cn
Jquery中文网 >  脚本编程  >  php  >  正文 php去除html标签获得输入纯文本文档strip_tags

php去除html标签获得输入纯文本文档strip_tags

发布时间:2015-05-12   编辑:www.jquerycn.cn
有时候可能需要将html文本转换为纯文本。<br /> 可以使用strip_tags()函数达到这个目的,该函数删除字符串中的所有html和php标记,只剩下文本实体。

其形式为:
strip_tags

(PHP 3 >= 3.0.8, PHP 4, PHP 5)
strip_tags -- Strip HTML and PHP tags from a string

Description
string strip_tags ( string str [, string allowable_tags] )

This function tries to return a string with all HTML and PHP tags stripped from a given str. It uses the same tag stripping state machine as the fgetss() function.
You can use the optional second parameter to specify tags which should not be stripped.

例子 1. strip_tags() example
 

复制代码 代码如下:
<?php
$text = '<p>Test paragraph.</p><!-- Comment --> Other text';
echo strip_tags($text);
echo "\n";
    
// Allow <p>
echo strip_tags($text, '<p>');
?>
 

上例将输出:
Test paragraph. Other text
<p>Test paragraph.</p> Other text

您可能感兴趣的文章:
php去除html标签获得输入纯文本文档strip_tags
php用strip_tags完整去除所有html标签的实例分享
php删除html标签及字符串中html标签的代码
php删除字符串中html标签的函数
PHP删除HTMl标签多种方法
php过滤html标记的函数strip_tags用法举例(图文)
php删除html标签的三种方法分享
php去除HTML标签的二种方法
php 去除多余的HTML标签
php去掉html标签函数代码

关键词: html标签  php去除html标签  strip_tags   
[关闭]