This article mainly introduces PHP filter all the blank characters of the method, interested in the friend's reference, I hope to be helpful to everyone.
The trim function in PHP can only replace the left and right spaces, feeling in some cases not so good, if you want to filter out all the whitespace characters in a string (spaces, full-width spaces, line wrapping, etc.), then we can write a filter function ourselves.
PHP Learning Str_replace functions are known, can be bulk replacement, so we can use the following source implementation to filter a string of all whitespace characters.
<?php$str = ' Jkgsdgsgsdgs gsdg GSD '; Echo Mytrim ($STR); function Mytrim ($str) {$search = Array ("," "," \ n "," \ r "," \ T "); $ Replace = Array ("", "", "", "", ""); Return Str_replace ($search, $replace, $str);}? >
Run code, page output:jkgsdgsgsdgsgsdggsd, perfect for the effect we want.
Summary: The above is the entire content of this article, I hope to be able to help you learn.