Multibyte trim in PHP?
Apparently there's no mb_trim in the mb_* family, so I'm trying to implement one for my own.
I recently found this regex in a comment in php.net:
/(^\s+)|(\s+$)/u
So, I'd implement it in the following way:
function multibyte_trim($str)
{
if (!function_exists("mb_trim") || !extension_loaded("mbstring")) {
return preg_replace("/(^\s+)|(\s+$)/u", "", $str);
} else {
return mb_trim($str);
}
}
The regex seems correct to me, but I'm extremely noob with regular expressions. Will this effectively remove any Unicode space in the beginning/end of a string?