免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1411 | 回复: 1
打印 上一主题 下一主题

请问如何在一行文本中去除其中的HTML标记 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-09-22 07:24 |只看该作者 |倒序浏览
我在手册里面找了一下,好像没有现成的函数。莫非要用正则表达式,可惜对正则表达式不太熟。请指教
我的目的是这样的:
如原文

  1. <a href='index.html'>hello world</a>
复制代码

处理后变成

  1. hello world
复制代码

论坛徽章:
0
2 [报告]
发表于 2006-09-22 08:10 |只看该作者
查手册得到的:
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.

注: allowable_tags was added in PHP 3.0.13 and PHP 4.0b3. Since PHP 4.3.0, HTML comments are also stripped.


警告
Because strip_tags() does not actually validate the HTML, partial, or broken tags can result in the removal of more text/data than expected.



例子 1. strip_tags() example

<?php
$text = '
<p>Test paragraph.</p>
<!-- Comment -->
Other text';

echo strip_tags($text);

echo "\n\n-------\n";

// allow <p>
echo strip_tags($text, '<p>');
?>  

The above example will output:

Test paragraph.

Other text

-------

<p>Test paragraph.</p>

Other text





警告
This function does not modify any attributes on the tags that you allow using allowable_tags, including the style and onmouseover attributes that a mischievous user may abuse when posting text that will be shown to other users.


See also htmlspecialchars().
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP