Skip to content

Instantly share code, notes, and snippets.

@xtfer
Created July 31, 2014 06:23
Show Gist options
  • Save xtfer/686ad2ea3bcab505502b to your computer and use it in GitHub Desktop.
Save xtfer/686ad2ea3bcab505502b to your computer and use it in GitHub Desktop.
<?php
/**
* Trim all odd characters.
*
* 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
*
* @param string $str
* the string to trim
*
* @return string
* The trimmed string.
*/
public function trimAll($str) {
$what = "\\x00-\\x20";
return trim(preg_replace("/[" . $what . "]+/", ' ', $str), $what);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment