租用问题

质量为本、客户为根、勇于拼搏、务实创新

< 返回租用问题列表

php字符串过滤strip_tags()函数用法实例分析,php字符串处理

发布时间:2023-08-14 08:35:04

php字符串过滤strip_tags()函数用法实例分析

strip_tags()函数用于过滤字符串中的HTML和PHP标签。
语法:
strip_tags(string $str, string $allowable_tags)
参数说明:
- $str:要过滤的字符串。
- $allowable_tags(可选):允许保存的标签。不指定时会过滤所有标签。
返回值:
返回过滤后的字符串。
示例:
```
$str = "

Hello, world!

";
echo strip_tags($str); // 输出:Hello, world!
$str = "

Hello, world!

";
echo strip_tags($str, ""); // 输出:Hello, world!
```
在第一个示例中,strip_tags()函数会过滤掉字符串中的所有HTML和PHP标签,只保存纯文本部份。
在第二个示例中,指定了第二个参数为"",strip_tags()函数会保存标签,其他标签都会被过滤掉。输出结果为包括标签的字符串。