新聞中心
這篇文章給大家介紹利用PHP怎么刪除字符串中無(wú)用的標(biāo)簽,內(nèi)容非常詳細(xì),感興趣的小伙伴們可以參考借鑒,希望對(duì)大家能有所幫助。
具體實(shí)現(xiàn)方法如下:
很多時(shí)候需要輸出一些 “純” 字符串,也就是去除任何雜質(zhì),例如 Html 標(biāo)簽、空格之類的文本,輸出的摘要就是如此,下面的這個(gè)函數(shù)可以幫你實(shí)現(xiàn)著一點(diǎn).
PHP實(shí)例代碼如下:
復(fù)制代碼 代碼如下:
function Bing_string_cleanr( $string ){
$string = trim( $string );
$string = strip_tags( $string );
$string = htmlspecialchars( $string, ENT_QUOTES, 'UTF-8' );
$string = str_replace( "n", "", $string );
$string = trim( $string );
return $string;
}
使用方法如下:
復(fù)制代碼 代碼如下:
echo Bing_string_cleanr( '內(nèi) 容
asdfeiuonsdfje' );
php刪除空白,代碼如下:
復(fù)制代碼 代碼如下:
$str = " This line containstliberal rn use of whitespace.nn";
// First remove the leading/trailing whitespace
//去掉開始和結(jié)束的空白
$str = trim($str);
// Now remove any doubled-up whitespace
//去掉跟隨別的擠在一塊的空白
$str = preg_replace('/s(?=s)/', '', $str);
// Finally, replace any non-space whitespace, with a space
//最后,去掉非space 的空白,用一個(gè)空格代替
$str = preg_replace('/[nrt]/', ' ', $str);
// Echo out: 'This line contains liberal use of whitespace.'
echo "
{$str}";
?>
關(guān)于利用PHP怎么刪除字符串中無(wú)用的標(biāo)簽就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,可以學(xué)到更多知識(shí)。如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到。
網(wǎng)站標(biāo)題:利用PHP怎么刪除字符串中無(wú)用的標(biāo)簽-創(chuàng)新互聯(lián)
鏈接分享:http://fisionsoft.com.cn/article/ppjop.html