Trim whitespace in unicode (multibyte) string in PHP Written by Krzysztof Dryja on March 31, 2014 in IT Stuff This might be helpful in many cases: preg_replace('/^[\p{Z}\s]+|[\p{Z}\s]+$/u','',$str); 1 preg_replace('/^[\p{Z}\s]+|[\p{Z}\s]+$/u','',$str); Some alternative methods on stackoverflow.