This article mainly introduces how PHP clears all useless tags in strings, and involves clearing spaces and html tags in strings. It is a very practical technique. For more information, see.
This article mainly introduces how PHP clears all useless tags in strings, and involves clearing spaces and html tags in strings. It is a very practical technique. For more information, see.
This example describes how to clear all useless tags in a string in PHP. Share it with you for your reference. The specific implementation method is as follows:
Many times, you need to output some "pure" strings, that is, to remove any impurities, such as Html tags, spaces, and other text. This is the output abstract, the following function can help you implement one point.
The PHP instance code is as follows:
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;
}
The usage is as follows:
The Code is as follows:
Echo Bing_string_cleanr ('internal capacity
Asdfeiuonsdfje ');
Php deletes the blank space. The Code is as follows:
The Code is as follows:
<? Php
$ Str = "This line containstliberal rn use of whitespace. nn ";
// First remove the leading/trailing whitespace
// Remove the start and end spaces.
$ Str = trim ($ str );
// Now remove any doubled-up whitespace
// Remove the blank space crowded with other items
$ Str = preg_replace ('/s (? = S)/', '', $ str );
// Finally, replace any non-space whitespace, with a space
// Finally, remove the non-space blank and replace it with a space.
$ Str = preg_replace ('/[nrt]/', '', $ str );
// Echo out: 'This line contains liberal use of whitespace .'
Echo"
{$str}
";
?>
I hope this article will help you with PHP programming.