Skip to content

Instantly share code, notes, and snippets.

@decodedmrq
Created February 2, 2021 15:03
Show Gist options
  • Save decodedmrq/8e07d1c98b67250c3dd5a79b4eabb0fd to your computer and use it in GitHub Desktop.
Save decodedmrq/8e07d1c98b67250c3dd5a79b4eabb0fd to your computer and use it in GitHub Desktop.
/**
* Remove space fullsize
*
* @param string $str string before remove
* @return string after removed
*/
public static function mb_trim($str, $chars = '\s ') {
$str = preg_replace("/^[$chars]+/u", '', $str);
$str = preg_replace("/[$chars]+$/u", '', $str);
return $str;
}
or
/**
* Trim space, tab
* @param string $value
* @return string
*/
public function trimSpace($value) {
mb_internal_encoding('UTF-8');
mb_regex_encoding('UTF-8');
$value = mb_ereg_replace("^[\n\r\s\t ]+", '', $value);
$value = mb_ereg_replace("[\n\r\s\t ]+$", '', $value);
$value = trim($value);
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment