最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php常用函数之strip_tags函数用法
时间:2022-06-24 19:49:38 编辑:袖梨 来源:一聚教程网
A,定义和用法
strip_tags() 函数去除字符串中的 HTML、XML 以及 PHP 的标签。
strip_tags(string,allow)
参数 描述
string 必需。规定要检查的字符串。
allow 可选。规定允许的标签。这些标签不会被删除。
注释:该函数始终会剥离 HTML 注释。这点无法通过 allow 参数改变。
B,例子
例1
echo strip_tags("Hello world!");
输出:
Hello world!
例2
echo strip_tags("Hello world!","");
输出:
Hello world!
例子3、 strip_tags() example
Test paragraph.
echo strip_tags($text, '
');?>
上例将输出:
Test paragraph. Other text
Test paragraph.
Other text
实例4:
$str = "Hello world!";
echo strip_tags($str);
echo '
';
echo strip_tags($str, '');
?>
输出结果:
Hello world!
Hello world!
例子5
如果要使用php删除html标记中的特定标签呢?
这个就需要代码来实现了,如下:
function strip_selected_tags($text, $tags = array())
{
$args = func_get_args();
$text = array_shift($args);
$tags = func_num_args() > 2 ? array_diff($args,array($text)) : (array)$tags;
foreach ($tags as $tag){
if( preg_match_all( '/<'.$tag.'[^>]*>([^<]*)'.$tag.'>/iu', $text, $found) ){
$text = str_replace($found[0],$found[1],$text);
}
}
return preg_replace( '/(<('.join('|',$tags).')( | |.)*/>)/iu', '', $text);
}
$str = "[url="]123[/url]";
echo strip_selected_tags($str,array('b'));
相关文章
- 最火全球交易所数字资产交易TOP10-去中心化比特币交易所币安推荐 06-16
- 《大侠立志传》全丙级刀怎么获取 06-16
- Namada Token是什么意思?解析NAM代币背景与生态价值 06-16
- 最新2025正规虚拟币交易平台榜单-最安全现货交易app币安推荐 06-16
- 《宝可梦大集结》快龙技能详尽介绍 06-16
- 《交错战线》坍陨技能有哪些优势 06-16