PHP clears all useless tags in the string, PHP string
This example describes how PHP cleans up all the useless tags in a string. Share to everyone for your reference. The implementation method is as follows:
Many times need to output some "pure" string, that is, to remove any impurities, such as Html tags, spaces, such as text, the output of the digest is so, the following function can help you achieve a point.
The PHP instance code is as follows:
Copy the Code code 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;
}
Here's how to use it:
Copy the Code code as follows: Echo Bing_string_cleanr (' content
Asdfeiuonsdfje ');
PHP Delete blank, the code is as follows:
Copy the Code code as follows: <?php
$STR = "This line containstliberal RN use of whitespace.nn";
First remove the leading/trailing whitespace
Remove the opening and closing blanks
$str = Trim ($STR);
Now remove any doubled-up whitespace
Remove the blank that follows the other squeeze
$str = Preg_replace ('/s (? =s)/', ' ', $str);
Finally, replace any non-space whitespace, with a space
Finally, remove the non-space space, with a space instead
$str = preg_replace ('/[nrt]/', ' ', $str);
Echo out: ' This line contains liberal use of whitespace. '
echo "
{$STR}
";
?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/920624.html www.bkjia.com true http://www.bkjia.com/PHPjc/920624.html techarticle PHP clears all the useless tags in the string, the PHP string example describes how PHP clears all the useless tags in the string. Share to everyone for your reference. Concrete implementation of the party ...