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; }
echo Bing_string_cleanr( '内 容 <br> <html> asdfeiuonsdfje' );
php删除空白,代码如下:
<?php $str = " This line containstliberal rn use of whitespace.nn"; // First remove the leading/trailing whitespace //去掉开始和结束的空白 $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程序设计有所帮助。