This example describes the way in which PHP clears all the unwanted tags in a string. Share to everyone for your reference. The implementation methods are as follows:
Many times you need to output some "pure" strings, that is, remove any impurities, such as Html tags, spaces and other text, the output of the summary is so, the following function can help you achieve a bit.
The PHP instance code is as follows:
Copy 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;
}
Use the following methods:
Copy Code code as follows:
echo bing_string_cleanr (' content <br>
PHP Delete blank, the code is as follows:
Copy Code code as follows:
<?php
$STR = "This line containstliberal RN with Whitespace.nn";
The leading/trailing whitespace
Remove the start and end blanks
$str = Trim ($STR);
Now remove any doubled-up whitespace
To take the rest of the space and squeeze it in.
$str = Preg_replace ('/s (? =s)/', ', $str);
Finally, replace any non-space whitespace and a space
Finally, remove the blank space, using a space instead
$str = preg_replace ('/[nrt]/', ', ', $str);
Echo out: ' This line contains liberal the use of whitespace. '
echo "<pre>{$str}</pre>";
?>
I hope this article will help you with your PHP program design.