Skip to content

Instantly share code, notes, and snippets.

@egulhan
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

  • Save egulhan/13d05a7d72405a3b183c to your computer and use it in GitHub Desktop.

Select an option

Save egulhan/13d05a7d72405a3b183c to your computer and use it in GitHub Desktop.
Trim all white-space characters using PHP
<?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