在前一阵在的面试过程中面试官曾经问我,如果字符串中的标签未闭合,strip_tags会如何处理?
在php的官方文档中对strip_tags的表述如下;
strip_tags ? 从字符串中去除 HTML 和 PHP 标记
注意文档下方的warning:
立即学习“PHP免费学习笔记(深入)”;
由于 strip_tags() 无法实际验证 HTML,不完整或者破损标签将导致更多的数据被删除。
这句话是什么意思呢?
通过下面的几个案例来向大家介绍
sample1:
$testStr1 = "<strong>hello world!";echo strip_tags($testStr1);
输出:
hello world!
sample2:
$testStr1 = "<strong>hello world!";echo strip_tags($testStr1);
hello world!
$testStr2 = "<stronghello world!</strong>";echo strip_tags($testStr2);
输出空字符串
sample4:
$testStr3 = "hello world1<stronghello world2!</strong>hello world3";echo strip_tags($testStr3);
hello world1
版权声明:本文为博主原创文章,未经博主允许不得转载。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号