From 6c4e2e9b8fdeac2405d55a7cc00f580f0b6c87c3 Mon Sep 17 00:00:00 2001 From: kink Date: Thu, 16 May 2013 12:16:58 +0000 Subject: [PATCH] Remove use of deprecated /e modifier in preg_replace. This modifier starts generating Deprecated notices from PHP 5.5. git-svn-id: https://svn.code.sf.net/p/squirrelmail/code/trunk/squirrelmail@14360 7612ce4b-ef26-0410-bec9-ea0150e637f0 --- functions/decode/iso_8859_1.php | 8 ++++++-- functions/decode/us_ascii.php | 4 ++-- functions/decode/utf_8.php | 22 +++++++++++----------- functions/encode/cp1251.php | 7 ++++--- functions/encode/cp1255.php | 7 ++++--- functions/encode/cp1256.php | 7 ++++--- functions/encode/iso_8859_1.php | 7 ++++--- functions/encode/iso_8859_15.php | 7 ++++--- functions/encode/iso_8859_2.php | 7 ++++--- functions/encode/iso_8859_7.php | 7 ++++--- functions/encode/iso_8859_9.php | 7 ++++--- functions/encode/koi8_r.php | 7 ++++--- functions/encode/koi8_u.php | 7 ++++--- functions/encode/tis_620.php | 7 ++++--- functions/encode/us_ascii.php | 7 ++++--- functions/encode/utf_8.php | 7 ++++--- functions/mime.php | 3 ++- 17 files changed, 73 insertions(+), 55 deletions(-) diff --git a/functions/decode/iso_8859_1.php b/functions/decode/iso_8859_1.php index c5f8ada0..b2317bc7 100644 --- a/functions/decode/iso_8859_1.php +++ b/functions/decode/iso_8859_1.php @@ -23,11 +23,15 @@ function charset_decode_iso_8859_1 ($string) { if (! sq_is8bit($string,'iso-8859-1')) return $string; - $string = preg_replace("/([\201-\237])/e","'&#' . ord('\\1') . ';'",$string); + $string = preg_replace_callback("/([\201-\237])/", + create_function ('$matches', 'return \'&#\' . ord($matches[1]) . \';\';'), + $string); /* I don't want to use 0xA0 (\240) in any ranges. RH73 may dislike it */ $string = str_replace("\240", ' ', $string); - $string = preg_replace("/([\241-\377])/e","'&#' . ord('\\1') . ';'",$string); + $string = preg_replace_callback("/([\241-\377])/", + create_function ('$matches', 'return \'&#\' . ord($matches[1]) . \';\';'), + $string); return $string; } diff --git a/functions/decode/us_ascii.php b/functions/decode/us_ascii.php index 93597ce1..5776d0e9 100644 --- a/functions/decode/us_ascii.php +++ b/functions/decode/us_ascii.php @@ -26,11 +26,11 @@ function charset_decode_us_ascii ($string) { if (! sq_is8bit($string,'us-ascii')) return $string; - $string = preg_replace("/([\201-\237])/e","'?'",$string); + $string = preg_replace("/([\201-\237])/","'?'",$string); /* I don't want to use 0xA0 (\240) in any ranges. RH73 may dislike it */ $string = str_replace("\240", '?', $string); - $string = preg_replace("/([\241-\377])/e","'?'",$string); + $string = preg_replace("/([\241-\377])/","'?'",$string); return $string; } diff --git a/functions/decode/utf_8.php b/functions/decode/utf_8.php index b6b1b3ee..53b1a99f 100644 --- a/functions/decode/utf_8.php +++ b/functions/decode/utf_8.php @@ -60,31 +60,31 @@ function charset_decode_utf_8 ($string) { // 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 /* (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 diff --git a/functions/encode/cp1251.php b/functions/encode/cp1251.php index 2afead9c..58a0282b 100644 --- a/functions/encode/cp1251.php +++ b/functions/encode/cp1251.php @@ -22,7 +22,7 @@ function charset_encode_cp1251 ($string) { // don't run encoding function, if there is no encoded characters if (! preg_match("'&#[0-9]+;'",$string) ) return $string; - $string=preg_replace("/&#([0-9]+);/e","unicodetocp1251('\\1')",$string); + $string=preg_replace_callback("/&#([0-9]+);/", 'unicodetocp1251', $string); return $string; } @@ -35,10 +35,11 @@ function charset_encode_cp1251 ($string) { * Don't use it or make sure, that functions/encode/cp1251.php is * included. * - * @param int $var decimal unicode value + * @param array $matches array with first element a decimal unicode value * @return string cp1251 character */ -function unicodetocp1251($var) { +function unicodetocp1251($matches) { + $var = $matches[1]; $cp1251chars=array('160' => "\xA0", '164' => "\xA4", diff --git a/functions/encode/cp1255.php b/functions/encode/cp1255.php index 3eca98c4..3b8ad0dd 100644 --- a/functions/encode/cp1255.php +++ b/functions/encode/cp1255.php @@ -22,7 +22,7 @@ function charset_encode_cp1255 ($string) { // don't run encoding function, if there is no encoded characters if (! preg_match("'&#[0-9]+;'",$string) ) return $string; - $string=preg_replace("/&#([0-9]+);/e","unicodetocp1255('\\1')",$string); + $string=preg_replace_callback("/&#([0-9]+);/",'unicodetocp1255',$string); return $string; } @@ -35,10 +35,11 @@ function charset_encode_cp1255 ($string) { * Don't use it or make sure, that functions/encode/cp1255.php is * included. * - * @param int $var decimal unicode value + * @param array $matches array with first element a decimal unicode value * @return string cp1255 character */ -function unicodetocp1255($var) { +function unicodetocp1255($matches) { + $var = $matches[1]; $cp1255chars=array('160' => "\xA0", '161' => "\xA1", diff --git a/functions/encode/cp1256.php b/functions/encode/cp1256.php index 8ff1430b..0f5ff0f4 100644 --- a/functions/encode/cp1256.php +++ b/functions/encode/cp1256.php @@ -22,7 +22,7 @@ function charset_encode_cp1256 ($string) { // don't run encoding function, if there is no encoded characters if (! preg_match("'&#[0-9]+;'",$string) ) return $string; - $string=preg_replace("/&#([0-9]+);/e","unicodetocp1256('\\1')",$string); + $string=preg_replace_callback("/&#([0-9]+);/",'unicodetocp1256',$string); return $string; } @@ -35,10 +35,11 @@ function charset_encode_cp1256 ($string) { * Don't use it or make sure, that functions/encode/cp1256.php is * included. * - * @param int $var decimal unicode value + * @param array $matches array with first element a decimal unicode value * @return string cp1256 character */ -function unicodetocp1256($var) { +function unicodetocp1256($matches) { + $var = $matches[1]; $cp1256chars=array('160' => "\xA0", '162' => "\xA2", diff --git a/functions/encode/iso_8859_1.php b/functions/encode/iso_8859_1.php index 32cc1681..579711bf 100644 --- a/functions/encode/iso_8859_1.php +++ b/functions/encode/iso_8859_1.php @@ -22,7 +22,7 @@ function charset_encode_iso_8859_1 ($string) { // don't run encoding function, if there is no encoded characters if (! preg_match("'&#[0-9]+;'",$string) ) return $string; - $string=preg_replace("/&#([0-9]+);/e","unicodetoiso88591('\\1')",$string); + $string=preg_replace_callback("/&#([0-9]+);/",'unicodetoiso88591',$string); return $string; } @@ -35,10 +35,11 @@ function charset_encode_iso_8859_1 ($string) { * Don't use it or make sure, that functions/encode/iso_8859_1.php is * included. * - * @param int $var decimal unicode value + * @param array $matches array with first element a decimal unicode value * @return string iso-8859-1 character */ -function unicodetoiso88591($var) { +function unicodetoiso88591($matches) { + $var = $matches[1]; if ($var < 256) { $ret = chr ($var); diff --git a/functions/encode/iso_8859_15.php b/functions/encode/iso_8859_15.php index 9180d959..ca246e4e 100644 --- a/functions/encode/iso_8859_15.php +++ b/functions/encode/iso_8859_15.php @@ -22,7 +22,7 @@ function charset_encode_iso_8859_15 ($string) { // don't run encoding function, if there is no encoded characters if (! preg_match("'&#[0-9]+;'",$string) ) return $string; - $string=preg_replace("/&#([0-9]+);/e","unicodetoiso885915('\\1')",$string); + $string=preg_replace_callback("/&#([0-9]+);/",'unicodetoiso885915',$string); return $string; } @@ -35,10 +35,11 @@ function charset_encode_iso_8859_15 ($string) { * Don't use it or make sure, that functions/encode/iso_8859_15.php is * included. * - * @param int $var decimal unicode value + * @param array $matches array with first element a decimal unicode value * @return string iso-8859-15 character */ -function unicodetoiso885915($var) { +function unicodetoiso885915($matches) { + $var = $matches[1]; $iso885915chars=array('160' => "\xA0", '161' => "\xA1", diff --git a/functions/encode/iso_8859_2.php b/functions/encode/iso_8859_2.php index 6b036461..2a9e6617 100644 --- a/functions/encode/iso_8859_2.php +++ b/functions/encode/iso_8859_2.php @@ -22,7 +22,7 @@ function charset_encode_iso_8859_2 ($string) { // don't run encoding function, if there is no encoded characters if (! preg_match("'&#[0-9]+;'",$string) ) return $string; - $string=preg_replace("/&#([0-9]+);/e","unicodetoiso88592('\\1')",$string); + $string=preg_replace_callback("/&#([0-9]+);/",'unicodetoiso88592',$string); return $string; } @@ -35,10 +35,11 @@ function charset_encode_iso_8859_2 ($string) { * Don't use it or make sure, that functions/encode/iso_8859_2.php is * included. * - * @param int $var decimal unicode value + * @param array $matches array with first element a decimal unicode value * @return string iso-8859-2 character */ -function unicodetoiso88592($var) { +function unicodetoiso88592($matches) { + $var = $matches[1]; $iso88592chars=array('160' => "\xA0", '164' => "\xA4", diff --git a/functions/encode/iso_8859_7.php b/functions/encode/iso_8859_7.php index ad8055cd..6d04b300 100644 --- a/functions/encode/iso_8859_7.php +++ b/functions/encode/iso_8859_7.php @@ -22,7 +22,7 @@ function charset_encode_iso_8859_7 ($string) { // don't run encoding function, if there is no encoded characters if (! preg_match("'&#[0-9]+;'",$string) ) return $string; - $string=preg_replace("/&#([0-9]+);/e","unicodetoiso88597('\\1')",$string); + $string=preg_replace_callback("/&#([0-9]+);/",'unicodetoiso88597',$string); return $string; } @@ -35,10 +35,11 @@ function charset_encode_iso_8859_7 ($string) { * Don't use it or make sure, that functions/encode/iso_8859_7.php is * included. * - * @param int $var decimal unicode value + * @param array $matches array with first element a decimal unicode value * @return string iso-8859-7 character */ -function unicodetoiso88597($var) { +function unicodetoiso88597($matches) { + $var = $matches[1]; $iso88597chars=array('160' => "\xA0", '163' => "\xA3", diff --git a/functions/encode/iso_8859_9.php b/functions/encode/iso_8859_9.php index 9c06a7cf..662cff24 100644 --- a/functions/encode/iso_8859_9.php +++ b/functions/encode/iso_8859_9.php @@ -22,7 +22,7 @@ function charset_encode_iso_8859_9 ($string) { // don't run encoding function, if there is no encoded characters if (! preg_match("'&#[0-9]+;'",$string) ) return $string; - $string=preg_replace("/&#([0-9]+);/e","unicodetoiso88599('\\1')",$string); + $string=preg_replace_callback("/&#([0-9]+);/",'unicodetoiso88599',$string); return $string; } @@ -35,10 +35,11 @@ function charset_encode_iso_8859_9 ($string) { * Don't use it or make sure, that functions/encode/iso_8859_9.php is * included. * - * @param int $var decimal unicode value + * @param array $matches array with first element a decimal unicode value * @return string iso-8859-9 character */ -function unicodetoiso88599($var) { +function unicodetoiso88599($matches) { + $var = $matches[1]; $iso88599chars=array('160' => "\xA0", '161' => "\xA1", diff --git a/functions/encode/koi8_r.php b/functions/encode/koi8_r.php index bdd209ed..7b220156 100644 --- a/functions/encode/koi8_r.php +++ b/functions/encode/koi8_r.php @@ -22,7 +22,7 @@ function charset_encode_koi8_r ($string) { // don't run encoding function, if there is no encoded characters if (! preg_match("'&#[0-9]+;'",$string) ) return $string; - $string=preg_replace("/&#([0-9]+);/e","unicodetokoi8r('\\1')",$string); + $string=preg_replace_callback("/&#([0-9]+);/",'unicodetokoi8r',$string); return $string; } @@ -35,10 +35,11 @@ function charset_encode_koi8_r ($string) { * Don't use it or make sure, that functions/encode/koi8_r.php is * included. * - * @param int $var decimal unicode value + * @param array $matches array with first element a decimal unicode value * @return string koi8-r character */ -function unicodetokoi8r($var) { +function unicodetokoi8r($matches) { + $var = $matches[1]; $koi8rchars=array('160' => "\x9A", '169' => "\xBF", diff --git a/functions/encode/koi8_u.php b/functions/encode/koi8_u.php index 49328c4a..33100036 100644 --- a/functions/encode/koi8_u.php +++ b/functions/encode/koi8_u.php @@ -22,7 +22,7 @@ function charset_encode_koi8_u ($string) { // don't run encoding function, if there is no encoded characters if (! preg_match("'&#[0-9]+;'",$string) ) return $string; - $string=preg_replace("/&#([0-9]+);/e","unicodetokoi8u('\\1')",$string); + $string=preg_replace_callback("/&#([0-9]+);/",'unicodetokoi8u',$string); return $string; } @@ -35,10 +35,11 @@ function charset_encode_koi8_u ($string) { * Don't use it or make sure, that functions/encode/koi8_u.php is * included. * - * @param int $var decimal unicode value + * @param array $matches array with first element a decimal unicode value * @return string koi8-u character */ -function unicodetokoi8u($var) { +function unicodetokoi8u($matches) { + $var = $matches[1]; $koi8uchars=array('160' => "\x9A", '169' => "\xBF", diff --git a/functions/encode/tis_620.php b/functions/encode/tis_620.php index 6b6d647b..6c3b05a1 100644 --- a/functions/encode/tis_620.php +++ b/functions/encode/tis_620.php @@ -22,7 +22,7 @@ function charset_encode_tis_620 ($string) { // don't run encoding function, if there is no encoded characters if (! preg_match("'&#[0-9]+;'",$string) ) return $string; - $string=preg_replace("/&#([0-9]+);/e","unicodetotis620('\\1')",$string); + $string=preg_replace_callback("/&#([0-9]+);/",'unicodetotis620',$string); return $string; } @@ -35,10 +35,11 @@ function charset_encode_tis_620 ($string) { * Don't use it or make sure, that functions/encode/tis_620.php is * included. * - * @param int $var decimal unicode value + * @param array $matches array with first element a decimal unicode value * @return string tis-620 character */ -function unicodetotis620($var) { +function unicodetotis620($matches) { + $var = $matches[1]; $tis620chars=array('3585' => "\xA1", '3586' => "\xA2", diff --git a/functions/encode/us_ascii.php b/functions/encode/us_ascii.php index e870b9ff..7c7d721e 100644 --- a/functions/encode/us_ascii.php +++ b/functions/encode/us_ascii.php @@ -22,7 +22,7 @@ function charset_encode_us_ascii ($string) { // don't run encoding function, if there is no encoded characters if (! preg_match("'&#[0-9]+;'",$string) ) return $string; - $string=preg_replace("/&#([0-9]+);/e","unicodetousascii('\\1')",$string); + $string=preg_replace_callback("/&#([0-9]+);/",'unicodetousascii',$string); return $string; } @@ -35,10 +35,11 @@ function charset_encode_us_ascii ($string) { * Don't use it or make sure, that functions/encode/us_ascii.php is * included. * - * @param int $var decimal unicode value + * @param array $matches array with first element a decimal unicode value * @return string us-ascii character */ -function unicodetousascii($var) { +function unicodetousascii($matches) { + $var = $matches[1]; if ($var < 128) { $ret = chr ($var); diff --git a/functions/encode/utf_8.php b/functions/encode/utf_8.php index 16b5f93a..b1dcb14f 100644 --- a/functions/encode/utf_8.php +++ b/functions/encode/utf_8.php @@ -26,7 +26,7 @@ function charset_encode_utf_8 ($string) { // don't run encoding function, if there is no encoded characters if (! preg_match("'&#[0-9]+;'",$string) ) return $string; - $string=preg_replace("/&#([0-9]+);/e","unicodetoutf8('\\1')",$string); + $string=preg_replace_callback("/&#([0-9]+);/",'unicodetoutf8',$string); return $string; } @@ -39,10 +39,11 @@ function charset_encode_utf_8 ($string) { * Don't use it or make sure, that functions/encode/utf_8.php is * included. * - * @param int $var decimal unicode value + * @param array $matches array with first element a decimal unicode value * @return string utf8 character */ -function unicodetoutf8($var) { +function unicodetoutf8($matches) { + $var = $matches[1]; if ($var < 128) { $ret = chr ($var); diff --git a/functions/mime.php b/functions/mime.php index 63d6d2df..15b456c4 100644 --- a/functions/mime.php +++ b/functions/mime.php @@ -867,7 +867,8 @@ function decodeHeader ($string, $utfencode=true,$htmlsafe=true,$decide=false) { break; case 'Q': $replace = str_replace('_', ' ', $res[4]); - $replace = preg_replace('/=([0-9a-f]{2})/ie', 'chr(hexdec("\1"))', + $replace = preg_replace_callback('/=([0-9a-f]{2})/i', + create_function ('$matches', 'return chr(hexdec($matches[1]));'), $replace); if ($utfencode) { if ($can_be_encoded) { -- 2.25.1