Skip to content

Instantly share code, notes, and snippets.

@Isinlor
Last active March 3, 2016 09:25
Show Gist options
  • Save Isinlor/64b164cd213bc194dd38 to your computer and use it in GitHub Desktop.
Save Isinlor/64b164cd213bc194dd38 to your computer and use it in GitHub Desktop.
Two functions to work with unicode whitespaces. See: http://php.net/manual/en/regexp.reference.unicode.php
<?php
$compactWhitespace = function ($string) {
return preg_replace('/[\pZ\pC]+/u', ' ', $string);
};
$trim = function ($string) {
return preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', $string);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment