This article mainly introduces 3 kinds of methods in PHP to remove the space in the middle of the string, you need friends can refer to the following
The first: Use regular code as follows: <?php echo Preg_replace (' # # ', ', ' ab AB '); Output "Abab"?> the second: Use the Str_replace () function code as follows: <?php Echo str_replace (', ', ' ab AB '); Output "Abab '?> third: Use the STRTR () function code as follows: <?php Echo strtr (' Ab ab ', Array (' => ')); The output "Abab"?> strtr () function is somewhat special, essentially: The code is as follows: <?php strtr (' ewb ', ' web ', ' 123 ') = = Strtr (' ewb ', Array (' E ' => ' 2 ', ' W ') => ' 1 ', ' B ' => ' 3 ') = = Str_replace (Array (' E ', ' W ', ' B '), Array (' 2 ', ' 1 ', ' 3 '), ' ewb ');?> Fourth: Use the encapsulation function code as follows: function Trimall ($STR)//delete space {$qian =array ("", "", "T", "N", "R"); $hou =array ("", "", "" "," "," "); Return Str_replace ($qian, $hou, $STR); }