Last active
August 29, 2015 14:20
-
-
Save egulhan/13d05a7d72405a3b183c to your computer and use it in GitHub Desktop.
Trim all white-space characters using PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // | |
| // source: http://pageconfig.com/post/remove-undesired-characters-with-trim_all-php | |
| // | |
| function trim_all( $str , $what = NULL , $with = ' ' ) | |
| { | |
| if( $what === NULL ) | |
| { | |
| // Character Decimal Use | |
| // "\0" 0 Null Character | |
| // "\t" 9 Tab | |
| // "\n" 10 New line | |
| // "\x0B" 11 Vertical Tab | |
| // "\r" 13 New Line in Mac | |
| // " " 32 Space | |
| $what = "\\x00-\\x20"; //all white-spaces and control chars | |
| } | |
| return trim( preg_replace( "/[".$what."]+/" , $with , $str ) , $what ); | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment