php strip_tags函數(shù)的用法是什么

PHP
小億
85
2024-03-01 15:22:14
欄目: 編程語言

strip_tags() 函數(shù)用于去除字符串中的 HTML 和 PHP 標(biāo)記。它的語法如下:

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

其中,參數(shù) str 是需要去除標(biāo)記的字符串,allowable_tags 是可選參數(shù),用于指定允許保留的標(biāo)記。

如果不指定 allowable_tags 參數(shù),函數(shù)將去除字符串中的所有標(biāo)記。如果指定了 allowable_tags 參數(shù),將保留指定的標(biāo)記,其他標(biāo)記將被去除。

例如:

$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