欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP清除字符串中所有無用標(biāo)簽的方法

 更新時間:2014年12月01日 14:24:50   投稿:shichen2014  
這篇文章主要介紹了PHP清除字符串中所有無用標(biāo)簽的方法,涉及針對字符串中空格、html標(biāo)簽等的清除,是非常實用的技巧,需要的朋友可以參考下

本文實例講述了PHP清除字符串中所有無用標(biāo)簽的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:

很多時候需要輸出一些 “純” 字符串,也就是去除任何雜質(zhì),例如 Html 標(biāo)簽、空格之類的文本,輸出的摘要就是如此,下面的這個函數(shù)可以幫你實現(xiàn)著一點(diǎn).

PHP實例代碼如下:

復(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) 容 <br> <html> asdfeiuonsdfje' );

php刪除空白,代碼如下:

復(fù)制代碼 代碼如下:
<?php
$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 的空白,用一個空格代替
$str = preg_replace('/[nrt]/', ' ', $str);
// Echo out: 'This line contains liberal use of whitespace.'
echo "<pre>{$str}</pre>";
?>

希望本文所述對大家的PHP程序設(shè)計有所幫助。

相關(guān)文章

最新評論