This article mainly describes how to replace and filter all blank characters in php, including spaces, full-angle spaces, and line breaks. Interested friends can study together.
This article mainly describes how to replace and filter all blank characters in php, including spaces, full-angle spaces, and line breaks. Interested friends can study together.
The self-contained trim function in php can only replace spaces on both sides of the left and right. In some cases, it may not be easy to use, if you want to filter out all the spaces (spaces, full-width spaces, line breaks, etc.) in a string, you can write a filter function by yourself.
Php learns str_replace functions and can be replaced in batches. Therefore, we can use the following source code to replace and filter all the blank characters in a string.
<? 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 the code and the page output: jkgsdgsgsdgsgsdggsd, which perfectly achieves the desired effect.
The above is the php Method for filtering all the blank characters. I hope it will be helpful for your learning.