ryanharne

Remove Excessive White Spaces from String / Object

Nov 14th, 2014
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.42 KB | None | 0 0
  1. function remove_white_spaces( $string = '', $true_trim = true ) {
  2.  
  3.   $return = '';
  4.  
  5.   if ( !empty( $string ) ) {
  6.  
  7.     if ( is_string( $string ) ) {
  8.  
  9.       $return = preg_replace( '/\s\s+/', ' ', $string );
  10.  
  11.       if( $true_trim ) {
  12.  
  13.         $return = trim( $return );
  14.       }
  15.  
  16.     } else { // is_string
  17.  
  18.       return array_map( __FUNCTION__ , $string );
  19.  
  20.     }    
  21.  
  22.   } // empty    
  23.  
  24.   return $return;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment