Happy New Year
[squirrelmail.git] / functions / decode / utf_8.php
index c6b1e61584d1d0c95ce3cca8a9449ced2a1a6e91..17048b7a869f039cabdef54293996d1212c39025 100644 (file)
@@ -1,10 +1,8 @@
 <?php
+
 /**
  * functions/decode/utf-8.php - utf-8 decoding functions
  *
- * Copyright (c) 2003-2004 The SquirrelMail Project Team
- * Licensed under the GNU GPL. For full terms see the file COPYING.
- *
  * This file contains utf-8 decoding function that is needed to read
  * utf-8 encoded mails in non-utf-8 locale.
  *
  *  octdec(a-340)*64^2 + octdec(b-200)*64 + octdec(c-200)
  *
  * \a\b\c\d characters are decoded to html code calculated with formula:
- *  octdec(a-360)*64^3 + octdec(b-200)*64^2 + 
+ *  octdec(a-360)*64^3 + octdec(b-200)*64^2 +
  *  + octdec(c-200)*64 + octdec(d-200)
  *
  * \a\b\c\d\e characters are decoded to html code calculated with formula:
- *  octdec(a-370)*64^4 + octdec(b-200)*64^3 + 
+ *  octdec(a-370)*64^4 + octdec(b-200)*64^3 +
  *  + octdec(c-200)*64^2 + octdec(d-200)*64 + octdec(e-200)
  *
  * \a\b\c\d\e\f characters are decoded to html code calculated with formula:
- *  octdec(a-374)*64^5 + octdec(b-200)*64^4 + octdec(c-200)*64^3 + 
+ *  octdec(a-374)*64^5 + octdec(b-200)*64^4 + octdec(c-200)*64^3 +
  *  + octdec(d-200)*64^2 + octdec(e-200)*64 + octdec(f-200)
  *</pre>
+ * @copyright 2003-2020 The SquirrelMail Project Team
+ * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  * @version $Id$
  * @package squirrelmail
  * @subpackage decode
@@ -58,33 +58,33 @@ function charset_decode_utf_8 ($string) {
     if (! sq_is8bit($string,'utf-8'))
         return $string;
 
-    // decode six byte unicode characters 
+    // decode six byte unicode characters
     /* (i think currently there is no such symbol)
-    $string = preg_replace("/([\374-\375])([\200-\277])([\200-\277])([\200-\277])([\200-\277])([\200-\277])/e",
-    "'&#'.((ord('\\1')-252)*1073741824+(ord('\\2')-200)*16777216+(ord('\\3')-200)*262144+(ord('\\4')-128)*4096+(ord('\\5')-128)*64+(ord('\\6')-128)).';'",
+    $string = preg_replace_callback("/([\374-\375])([\200-\277])([\200-\277])([\200-\277])([\200-\277])([\200-\277])/",
+    create_function ('$matches', 'return \'&#\'.((ord($matches[1])-252)*1073741824+(ord($matches[2])-200)*16777216+(ord($matches[3])-200)*262144+(ord($matches[4])-128)*4096+(ord($matches[5])-128)*64+(ord($matches[6])-128)).\';\';'),
     $string);
     */
 
-    // decode five byte unicode characters 
+    // decode five byte unicode characters
     /* (i think currently there is no such symbol)
-    $string = preg_replace("/([\370-\373])([\200-\277])([\200-\277])([\200-\277])([\200-\277])/e",
-    "'&#'.((ord('\\1')-248)*16777216+(ord('\\2')-200)*262144+(ord('\\3')-128)*4096+(ord('\\4')-128)*64+(ord('\\5')-128)).';'",
+    $string = preg_replace_callback("/([\370-\373])([\200-\277])([\200-\277])([\200-\277])([\200-\277])/",
+    create_function ('$matches', 'return \'&#\'.((ord($matches[1])-248)*16777216+(ord($matches[2])-200)*262144+(ord($matches[3])-128)*4096+(ord($matches[4])-128)*64+(ord($matches[5])-128)).\';\';'),
     $string);
     */
-
+    
     // decode four byte unicode characters
-    $string = preg_replace("/([\360-\367])([\200-\277])([\200-\277])([\200-\277])/e",
-    "'&#'.((ord('\\1')-240)*262144+(ord('\\2')-128)*4096+(ord('\\3')-128)*64+(ord('\\4')-128)).';'",
+    $string = preg_replace_callback("/([\360-\367])([\200-\277])([\200-\277])([\200-\277])/",
+    create_function ('$matches', 'return \'&#\'.((ord($matches[1])-240)*262144+(ord($matches[2])-128)*4096+(ord($matches[3])-128)*64+(ord($matches[4])-128)).\';\';'),
     $string);
 
     // decode three byte unicode characters
-    $string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e",
-    "'&#'.((ord('\\1')-224)*4096+(ord('\\2')-128)*64+(ord('\\3')-128)).';'",
+    $string = preg_replace_callback("/([\340-\357])([\200-\277])([\200-\277])/",
+    create_function ('$matches', 'return \'&#\'.((ord($matches[1])-224)*4096+(ord($matches[2])-128)*64+(ord($matches[3])-128)).\';\';'),
     $string);
 
     // decode two byte unicode characters
-    $string = preg_replace("/([\300-\337])([\200-\277])/e",
-    "'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'",
+    $string = preg_replace_callback("/([\300-\337])([\200-\277])/",
+    create_function ('$matches', 'return \'&#\'.((ord($matches[1])-192)*64+(ord($matches[2])-128)).\';\';'),
     $string);
 
     // remove broken unicode
@@ -92,4 +92,3 @@ function charset_decode_utf_8 ($string) {
 
     return $string;
 }
-?>
\ No newline at end of file