温馨提示×

php strip_tags函数的用法是什么

PHP
小亿
82
2024-03-01 15:22:14
栏目: 编程语言

strip_tags() 函数用于去除字符串中的 HTML 和 PHP 标记。它的语法如下:

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

其中,参数 str 是需要去除标记的字符串,allowable_tags 是可选参数,用于指定允许保留的标记。

如果不指定 allowable_tags 参数,函数将去除字符串中的所有标记。如果指定了 allowable_tags 参数,将保留指定的标记,其他标记将被去除。

例如:

$text = "<p>This is a <b>bold</b> and <i>italic</i> text.</p>";
echo strip_tags($text); // 输出:This is a bold and italic text.
echo strip_tags($text, "<b>"); // 输出:<p>This is a <b>bold</b> and italic text.</p>

0