X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FUtils.php;h=35d652241bb6a5a4c42c7ded7b7381be48dc7f15;hb=b3051a6aae446e063c3b6fa4a6a600357a9f24af;hp=62902341aee1a3d2bea676c8bbe3a53a2a721984;hpb=e0177549c760b143efdd17b1579e0c0199dce939;p=github%2Fshaarli%2FShaarli.git diff --git a/application/Utils.php b/application/Utils.php index 62902341..35d65224 100644 --- a/application/Utils.php +++ b/application/Utils.php @@ -257,3 +257,16 @@ function generate_api_secret($username, $salt) return str_shuffle(substr(hash_hmac('sha512', uniqid($salt), $username), 10, 12)); } + +/** + * Trim string, replace sequences of whitespaces by a single space. + * PHP equivalent to `normalize-space` XSLT function. + * + * @param string $string Input string. + * + * @return mixed Normalized string. + */ +function normalize_spaces($string) +{ + return preg_replace('/\s{2,}/', ' ', trim($string)); +}