mirror of
https://github.com/phpbb/phpbb.git
synced 2025-05-05 23:25:30 +02:00
[ticket/9669] Add native Normalizer support
PHP 5.3 includes the previous pecl extension "intl" which has a native UTF-8 normalizer. PHPBB3-9669
This commit is contained in:
parent
e8def259ef
commit
e8cc26e79c
@ -1712,15 +1712,17 @@ function utf8_case_fold_nfc($text, $option = 'full')
|
||||
return $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* A wrapper function for the normalizer which takes care of including the class if required and modifies the passed strings
|
||||
* to be in NFC (Normalization Form Composition).
|
||||
*
|
||||
* @param mixed $strings a string or an array of strings to normalize
|
||||
* @return mixed the normalized content, preserving array keys if array given.
|
||||
*/
|
||||
function utf8_normalize_nfc($strings)
|
||||
if (!extension_loaded('intl'))
|
||||
{
|
||||
/**
|
||||
* A wrapper function for the normalizer which takes care of including the class if required and modifies the passed strings
|
||||
* to be in NFC (Normalization Form Composition).
|
||||
*
|
||||
* @param mixed $strings a string or an array of strings to normalize
|
||||
* @return mixed the normalized content, preserving array keys if array given.
|
||||
*/
|
||||
function utf8_normalize_nfc($strings)
|
||||
{
|
||||
if (empty($strings))
|
||||
{
|
||||
return $strings;
|
||||
@ -1755,6 +1757,49 @@ function utf8_normalize_nfc($strings)
|
||||
}
|
||||
|
||||
return $strings;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/**
|
||||
* wrapper around PHP's native normalizer from intl
|
||||
* previously a PECL extension, included in the core since PHP 5.3.0
|
||||
* http://php.net/manual/en/normalizer.normalize.php
|
||||
*
|
||||
* @param mixed $strings a string or an array of strings to normalize
|
||||
* @return mixed the normalized content, preserving array keys if array given.
|
||||
*/
|
||||
function utf8_normalize_nfc($strings)
|
||||
{
|
||||
if (empty($strings))
|
||||
{
|
||||
return $strings;
|
||||
}
|
||||
|
||||
if (!is_array($strings))
|
||||
{
|
||||
$strings = Normalizer::normalize($strings);
|
||||
}
|
||||
if (is_array($strings))
|
||||
{
|
||||
foreach ($strings as $key => $string)
|
||||
{
|
||||
if (is_array($string))
|
||||
{
|
||||
foreach ($string as $_key => $_string)
|
||||
{
|
||||
$strings[$key][$_key] = Normalizer::normalize($strings[$key][$_key]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$strings[$key] = Normalizer::normalize($strings[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $strings;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user