Home >Backend Development >PHP Tutorial >PHP method to clear all useless tags in a string, php string_PHP tutorial

PHP method to clear all useless tags in a string, php string_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:12:31872browse

PHP method to clear all useless tags in a string, php string

The example in this article describes how PHP removes all useless tags in strings. Share it with everyone for your reference. The specific implementation method is as follows:

Many times it is necessary to output some "pure" strings, that is, remove any impurities, such as HTML tags, spaces and other text. The output summary is just like this. The following function can help you achieve this.

PHP example code is as follows:

Copy code The code is as follows:
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;
}

How to use:
Copy code The code is as follows:
echo Bing_string_cleanr( 'content
asdfeiuonsdfje' );

php deletes blank spaces, the code is as follows:

Copy code The code is as follows:
$str = "This line containsliberal rn use of whitespace.nn";

// First remove the leading/trailing whitespace
//Remove the starting and ending whitespace
$str = trim($str);

// Now remove any doubled-up whitespace
//Remove the white space that is crowded with others
$str = preg_replace('/s(?=s)/', '', $str);

// Finally, replace any non-space whitespace, with a space
//Finally, remove non-space whitespace and replace
with a space $str = preg_replace('/[nrt]/', ' ', $str);
// Echo out: 'This line contains liberal use of whitespace.'
echo "
{$str}
";
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/920624.htmlTechArticlePHP method to clear all useless tags in a string, php string This article tells the example of PHP clearing all useless tags in a string Useless tag method. Share it with everyone for your reference. Specific implementation method...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn