diff options
| author | 3D-I <480857+3D-I@users.noreply.github.com> | 2019-10-28 21:11:42 +0100 | 
|---|---|---|
| committer | 3D-I <480857+3D-I@users.noreply.github.com> | 2019-10-28 21:11:42 +0100 | 
| commit | d136a8a9078b02433f4be08420486ad05c8129bd (patch) | |
| tree | 4d3c720253ed2edef075bec7152a0ce66db16e10 /phpBB/includes/utf/utf_tools.php | |
| parent | 41728f2258c409480b9c3d4c1753b6eb1b47c677 (diff) | |
| parent | e95e387188b050c163edcce3141c957d259810c9 (diff) | |
| download | forums-d136a8a9078b02433f4be08420486ad05c8129bd.tar forums-d136a8a9078b02433f4be08420486ad05c8129bd.tar.gz forums-d136a8a9078b02433f4be08420486ad05c8129bd.tar.bz2 forums-d136a8a9078b02433f4be08420486ad05c8129bd.tar.xz forums-d136a8a9078b02433f4be08420486ad05c8129bd.zip | |
Merge branch '3.2.x' into ticket/16153
Diffstat (limited to 'phpBB/includes/utf/utf_tools.php')
| -rw-r--r-- | phpBB/includes/utf/utf_tools.php | 43 | 
1 files changed, 31 insertions, 12 deletions
| diff --git a/phpBB/includes/utf/utf_tools.php b/phpBB/includes/utf/utf_tools.php index 89de454427..bb155aeae5 100644 --- a/phpBB/includes/utf/utf_tools.php +++ b/phpBB/includes/utf/utf_tools.php @@ -418,24 +418,43 @@ function utf8_recode($string, $encoding)  }  /** -* Replace all UTF-8 chars that are not in ASCII with their NCR -* -* @param	string	$text		UTF-8 string in NFC -* @return	string				ASCII string using NCRs for non-ASCII chars -*/ + * Replace some special UTF-8 chars that are not in ASCII with their UCR. + * using their Numeric Character Reference's Hexadecimal notation. + * + * Doesn't interfere with Japanese or Cyrillic etc. + * Unicode character visualization will depend on the character support + * of your web browser and the fonts installed on your system. + * + * @see https://en.wikibooks.org/wiki/Unicode/Character_reference/1F000-1FFFF + * + * @param	string	$text		UTF-8 string in NFC + * @return	string				ASCII string using NCR for non-ASCII chars + */ +function utf8_encode_ucr($text) +{ +	return preg_replace_callback('/[\\xF0-\\xF4].../', 'utf8_encode_ncr_callback', $text); +} + +/** + * Replace all UTF-8 chars that are not in ASCII with their NCR + * using their Numeric Character Reference's Hexadecimal notation. + * + * @param	string	$text		UTF-8 string in NFC + * @return	string				ASCII string using NCRs for non-ASCII chars + */  function utf8_encode_ncr($text)  {  	return preg_replace_callback('#[\\xC2-\\xF4][\\x80-\\xBF]{1,3}#', 'utf8_encode_ncr_callback', $text);  }  /** -* Callback used in encode_ncr() -* -* Takes a UTF-8 char and replaces it with its NCR. Attention, $m is an array -* -* @param	array	$m			0-based numerically indexed array passed by preg_replace_callback() -* @return	string				A HTML NCR if the character is valid, or the original string otherwise -*/ + * Callback used in utf8_encode_ncr() and utf8_encode_ucr() + * + * Takes a UTF-8 char and replaces it with its NCR. Attention, $m is an array + * + * @param	array	$m			0-based numerically indexed array passed by preg_replace_callback() + * @return	string				A HTML NCR if the character is valid, or the original string otherwise + */  function utf8_encode_ncr_callback($m)  {  	return '&#' . utf8_ord($m[0]) . ';'; | 
