strip_tags()函數是PHP中的內置函數,用於從HTML和PHP標記中剝離字符串。此函數返回一個字符串,其中包含所有NULL字節,從給定的$str中剝離的HTML和PHP標記。
用法:
string strip_tags( $str, $allowable_tags )
參數:該函數接受上述和以下描述的兩個參數:
- $string:這是必需參數,它指定要檢查的字符串。
- $allow:它是一個可選參數,用於指定允許的標簽。這些標簽不會被刪除。
返回值:此函數返回剝離的字符串。
異常:
- 該函數去除HTML注釋和PHP標記。在$allow標記中不能使用它,因為它已經被硬編碼。
- PHP 5.3.4及更高版本,忽略了self-closing XHTML標記
- strip_tags()不驗證HTML。
以下示例程序旨在說明PHP中的strip_tags()函數:
程序1:
<?php
// PHP programme to illustrate
// strip_function without $allow parameter
echo strip_tags("Hello <b>GeeksforGeeks!</b>");
?>
輸出:
Hello GeeksforGeeks!
程序2:
<?php
// PHP programme to illustrate
// strip_function with $allow parameter
echo strip_tags("Hello <b><i>GeeksorGeeks!</i></b>", "<b>");
?>
輸出:
Hello <b>GeeksorGeeks!</b>
相關文章:
參考: http://php.net/manual/en/function.strip-tags.php
相關用法
- PHP exp()用法及代碼示例
- PHP Ds\Map put()用法及代碼示例
- PHP sin( )用法及代碼示例
- PHP abs()用法及代碼示例
- PHP cos( )用法及代碼示例
- PHP tan( )用法及代碼示例
- PHP next()用法及代碼示例
- PHP Ds\Map get()用法及代碼示例
- PHP pi( )用法及代碼示例
- PHP pow( )用法及代碼示例
- PHP Ds\Set get()用法及代碼示例
- PHP Ds\Map xor()用法及代碼示例
- PHP Ds\Set sum()用法及代碼示例
注:本文由純淨天空篩選整理自R_Raj大神的英文原創作品 PHP | strip_tags() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。