Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/updraftp.../vendor/symfony/polyfill...
File: Mbstring.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/*
[2] Fix | Delete
* This file is part of the Symfony package.
[3] Fix | Delete
*
[4] Fix | Delete
* (c) Fabien Potencier <fabien@symfony.com>
[5] Fix | Delete
*
[6] Fix | Delete
* For the full copyright and license information, please view the LICENSE
[7] Fix | Delete
* file that was distributed with this source code.
[8] Fix | Delete
*/
[9] Fix | Delete
[10] Fix | Delete
namespace Symfony\Polyfill\Mbstring;
[11] Fix | Delete
[12] Fix | Delete
/**
[13] Fix | Delete
* Partial mbstring implementation in PHP, iconv based, UTF-8 centric.
[14] Fix | Delete
*
[15] Fix | Delete
* Implemented:
[16] Fix | Delete
* - mb_chr - Returns a specific character from its Unicode code point
[17] Fix | Delete
* - mb_convert_encoding - Convert character encoding
[18] Fix | Delete
* - mb_convert_variables - Convert character code in variable(s)
[19] Fix | Delete
* - mb_decode_mimeheader - Decode string in MIME header field
[20] Fix | Delete
* - mb_encode_mimeheader - Encode string for MIME header XXX NATIVE IMPLEMENTATION IS REALLY BUGGED
[21] Fix | Delete
* - mb_decode_numericentity - Decode HTML numeric string reference to character
[22] Fix | Delete
* - mb_encode_numericentity - Encode character to HTML numeric string reference
[23] Fix | Delete
* - mb_convert_case - Perform case folding on a string
[24] Fix | Delete
* - mb_detect_encoding - Detect character encoding
[25] Fix | Delete
* - mb_get_info - Get internal settings of mbstring
[26] Fix | Delete
* - mb_http_input - Detect HTTP input character encoding
[27] Fix | Delete
* - mb_http_output - Set/Get HTTP output character encoding
[28] Fix | Delete
* - mb_internal_encoding - Set/Get internal character encoding
[29] Fix | Delete
* - mb_list_encodings - Returns an array of all supported encodings
[30] Fix | Delete
* - mb_ord - Returns the Unicode code point of a character
[31] Fix | Delete
* - mb_output_handler - Callback function converts character encoding in output buffer
[32] Fix | Delete
* - mb_scrub - Replaces ill-formed byte sequences with substitute characters
[33] Fix | Delete
* - mb_strlen - Get string length
[34] Fix | Delete
* - mb_strpos - Find position of first occurrence of string in a string
[35] Fix | Delete
* - mb_strrpos - Find position of last occurrence of a string in a string
[36] Fix | Delete
* - mb_str_split - Convert a string to an array
[37] Fix | Delete
* - mb_strtolower - Make a string lowercase
[38] Fix | Delete
* - mb_strtoupper - Make a string uppercase
[39] Fix | Delete
* - mb_substitute_character - Set/Get substitution character
[40] Fix | Delete
* - mb_substr - Get part of string
[41] Fix | Delete
* - mb_stripos - Finds position of first occurrence of a string within another, case insensitive
[42] Fix | Delete
* - mb_stristr - Finds first occurrence of a string within another, case insensitive
[43] Fix | Delete
* - mb_strrchr - Finds the last occurrence of a character in a string within another
[44] Fix | Delete
* - mb_strrichr - Finds the last occurrence of a character in a string within another, case insensitive
[45] Fix | Delete
* - mb_strripos - Finds position of last occurrence of a string within another, case insensitive
[46] Fix | Delete
* - mb_strstr - Finds first occurrence of a string within another
[47] Fix | Delete
* - mb_strwidth - Return width of string
[48] Fix | Delete
* - mb_substr_count - Count the number of substring occurrences
[49] Fix | Delete
*
[50] Fix | Delete
* Not implemented:
[51] Fix | Delete
* - mb_convert_kana - Convert "kana" one from another ("zen-kaku", "han-kaku" and more)
[52] Fix | Delete
* - mb_ereg_* - Regular expression with multibyte support
[53] Fix | Delete
* - mb_parse_str - Parse GET/POST/COOKIE data and set global variable
[54] Fix | Delete
* - mb_preferred_mime_name - Get MIME charset string
[55] Fix | Delete
* - mb_regex_encoding - Returns current encoding for multibyte regex as string
[56] Fix | Delete
* - mb_regex_set_options - Set/Get the default options for mbregex functions
[57] Fix | Delete
* - mb_send_mail - Send encoded mail
[58] Fix | Delete
* - mb_split - Split multibyte string using regular expression
[59] Fix | Delete
* - mb_strcut - Get part of string
[60] Fix | Delete
* - mb_strimwidth - Get truncated string with specified width
[61] Fix | Delete
*
[62] Fix | Delete
* @author Nicolas Grekas <p@tchwork.com>
[63] Fix | Delete
*
[64] Fix | Delete
* @internal
[65] Fix | Delete
*/
[66] Fix | Delete
final class Mbstring
[67] Fix | Delete
{
[68] Fix | Delete
const MB_CASE_FOLD = PHP_INT_MAX;
[69] Fix | Delete
[70] Fix | Delete
private static $encodingList = array('ASCII', 'UTF-8');
[71] Fix | Delete
private static $language = 'neutral';
[72] Fix | Delete
private static $internalEncoding = 'UTF-8';
[73] Fix | Delete
private static $caseFold = array(
[74] Fix | Delete
array('µ', 'ſ', "\xCD\x85", 'ς', "\xCF\x90", "\xCF\x91", "\xCF\x95", "\xCF\x96", "\xCF\xB0", "\xCF\xB1", "\xCF\xB5", "\xE1\xBA\x9B", "\xE1\xBE\xBE"),
[75] Fix | Delete
array('μ', 's', 'ι', 'σ', 'β', 'θ', 'φ', 'π', 'κ', 'ρ', 'ε', "\xE1\xB9\xA1", 'ι'),
[76] Fix | Delete
);
[77] Fix | Delete
[78] Fix | Delete
public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null)
[79] Fix | Delete
{
[80] Fix | Delete
if (\is_array($fromEncoding) || false !== strpos($fromEncoding, ',')) {
[81] Fix | Delete
$fromEncoding = self::mb_detect_encoding($s, $fromEncoding);
[82] Fix | Delete
} else {
[83] Fix | Delete
$fromEncoding = self::getEncoding($fromEncoding);
[84] Fix | Delete
}
[85] Fix | Delete
[86] Fix | Delete
$toEncoding = self::getEncoding($toEncoding);
[87] Fix | Delete
[88] Fix | Delete
if ('BASE64' === $fromEncoding) {
[89] Fix | Delete
$s = base64_decode($s);
[90] Fix | Delete
$fromEncoding = $toEncoding;
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
if ('BASE64' === $toEncoding) {
[94] Fix | Delete
return base64_encode($s);
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) {
[98] Fix | Delete
if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) {
[99] Fix | Delete
$fromEncoding = 'Windows-1252';
[100] Fix | Delete
}
[101] Fix | Delete
if ('UTF-8' !== $fromEncoding) {
[102] Fix | Delete
$s = iconv($fromEncoding, 'UTF-8//IGNORE', $s);
[103] Fix | Delete
}
[104] Fix | Delete
[105] Fix | Delete
return preg_replace_callback('/[\x80-\xFF]+/', array(__CLASS__, 'html_encoding_callback'), $s);
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
if ('HTML-ENTITIES' === $fromEncoding) {
[109] Fix | Delete
$s = html_entity_decode($s, ENT_COMPAT, 'UTF-8');
[110] Fix | Delete
$fromEncoding = 'UTF-8';
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
return iconv($fromEncoding, $toEncoding.'//IGNORE', $s);
[114] Fix | Delete
}
[115] Fix | Delete
[116] Fix | Delete
public static function mb_convert_variables($toEncoding, $fromEncoding, &$a = null, &$b = null, &$c = null, &$d = null, &$e = null, &$f = null)
[117] Fix | Delete
{
[118] Fix | Delete
$vars = array(&$a, &$b, &$c, &$d, &$e, &$f);
[119] Fix | Delete
[120] Fix | Delete
$ok = true;
[121] Fix | Delete
array_walk_recursive($vars, function (&$v) use (&$ok, $toEncoding, $fromEncoding) {
[122] Fix | Delete
if (false === $v = Mbstring::mb_convert_encoding($v, $toEncoding, $fromEncoding)) {
[123] Fix | Delete
$ok = false;
[124] Fix | Delete
}
[125] Fix | Delete
});
[126] Fix | Delete
[127] Fix | Delete
return $ok ? $fromEncoding : false;
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
public static function mb_decode_mimeheader($s)
[131] Fix | Delete
{
[132] Fix | Delete
return iconv_mime_decode($s, 2, self::$internalEncoding);
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null)
[136] Fix | Delete
{
[137] Fix | Delete
trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', E_USER_WARNING);
[138] Fix | Delete
}
[139] Fix | Delete
[140] Fix | Delete
public static function mb_decode_numericentity($s, $convmap, $encoding = null)
[141] Fix | Delete
{
[142] Fix | Delete
if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) {
[143] Fix | Delete
trigger_error('mb_decode_numericentity() expects parameter 1 to be string, '.\gettype($s).' given', E_USER_WARNING);
[144] Fix | Delete
[145] Fix | Delete
return null;
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
if (!\is_array($convmap) || !$convmap) {
[149] Fix | Delete
return false;
[150] Fix | Delete
}
[151] Fix | Delete
[152] Fix | Delete
if (null !== $encoding && !\is_scalar($encoding)) {
[153] Fix | Delete
trigger_error('mb_decode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', E_USER_WARNING);
[154] Fix | Delete
[155] Fix | Delete
return ''; // Instead of null (cf. mb_encode_numericentity).
[156] Fix | Delete
}
[157] Fix | Delete
[158] Fix | Delete
$s = (string) $s;
[159] Fix | Delete
if ('' === $s) {
[160] Fix | Delete
return '';
[161] Fix | Delete
}
[162] Fix | Delete
[163] Fix | Delete
$encoding = self::getEncoding($encoding);
[164] Fix | Delete
[165] Fix | Delete
if ('UTF-8' === $encoding) {
[166] Fix | Delete
$encoding = null;
[167] Fix | Delete
if (!preg_match('//u', $s)) {
[168] Fix | Delete
$s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
[169] Fix | Delete
}
[170] Fix | Delete
} else {
[171] Fix | Delete
$s = iconv($encoding, 'UTF-8//IGNORE', $s);
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
$cnt = floor(\count($convmap) / 4) * 4;
[175] Fix | Delete
[176] Fix | Delete
for ($i = 0; $i < $cnt; $i += 4) {
[177] Fix | Delete
// collector_decode_htmlnumericentity ignores $convmap[$i + 3]
[178] Fix | Delete
$convmap[$i] += $convmap[$i + 2];
[179] Fix | Delete
$convmap[$i + 1] += $convmap[$i + 2];
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
$s = preg_replace_callback('/&#(?:0*([0-9]+)|x0*([0-9a-fA-F]+))(?!&);?/', function (array $m) use ($cnt, $convmap) {
[183] Fix | Delete
$c = isset($m[2]) ? (int) hexdec($m[2]) : $m[1];
[184] Fix | Delete
for ($i = 0; $i < $cnt; $i += 4) {
[185] Fix | Delete
if ($c >= $convmap[$i] && $c <= $convmap[$i + 1]) {
[186] Fix | Delete
return Mbstring::mb_chr($c - $convmap[$i + 2]);
[187] Fix | Delete
}
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
return $m[0];
[191] Fix | Delete
}, $s);
[192] Fix | Delete
[193] Fix | Delete
if (null === $encoding) {
[194] Fix | Delete
return $s;
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
return iconv('UTF-8', $encoding.'//IGNORE', $s);
[198] Fix | Delete
}
[199] Fix | Delete
[200] Fix | Delete
public static function mb_encode_numericentity($s, $convmap, $encoding = null, $is_hex = false)
[201] Fix | Delete
{
[202] Fix | Delete
if (null !== $s && !\is_scalar($s) && !(\is_object($s) && \method_exists($s, '__toString'))) {
[203] Fix | Delete
trigger_error('mb_encode_numericentity() expects parameter 1 to be string, '.\gettype($s).' given', E_USER_WARNING);
[204] Fix | Delete
[205] Fix | Delete
return null;
[206] Fix | Delete
}
[207] Fix | Delete
[208] Fix | Delete
if (!\is_array($convmap) || !$convmap) {
[209] Fix | Delete
return false;
[210] Fix | Delete
}
[211] Fix | Delete
[212] Fix | Delete
if (null !== $encoding && !\is_scalar($encoding)) {
[213] Fix | Delete
trigger_error('mb_encode_numericentity() expects parameter 3 to be string, '.\gettype($s).' given', E_USER_WARNING);
[214] Fix | Delete
[215] Fix | Delete
return null; // Instead of '' (cf. mb_decode_numericentity).
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
if (null !== $is_hex && !\is_scalar($is_hex)) {
[219] Fix | Delete
trigger_error('mb_encode_numericentity() expects parameter 4 to be boolean, '.\gettype($s).' given', E_USER_WARNING);
[220] Fix | Delete
[221] Fix | Delete
return null;
[222] Fix | Delete
}
[223] Fix | Delete
[224] Fix | Delete
$s = (string) $s;
[225] Fix | Delete
if ('' === $s) {
[226] Fix | Delete
return '';
[227] Fix | Delete
}
[228] Fix | Delete
[229] Fix | Delete
$encoding = self::getEncoding($encoding);
[230] Fix | Delete
[231] Fix | Delete
if ('UTF-8' === $encoding) {
[232] Fix | Delete
$encoding = null;
[233] Fix | Delete
if (!preg_match('//u', $s)) {
[234] Fix | Delete
$s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
[235] Fix | Delete
}
[236] Fix | Delete
} else {
[237] Fix | Delete
$s = iconv($encoding, 'UTF-8//IGNORE', $s);
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
static $ulenMask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4);
[241] Fix | Delete
[242] Fix | Delete
$cnt = floor(\count($convmap) / 4) * 4;
[243] Fix | Delete
$i = 0;
[244] Fix | Delete
$len = \strlen($s);
[245] Fix | Delete
$result = '';
[246] Fix | Delete
[247] Fix | Delete
while ($i < $len) {
[248] Fix | Delete
$ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"];
[249] Fix | Delete
$uchr = substr($s, $i, $ulen);
[250] Fix | Delete
$i += $ulen;
[251] Fix | Delete
$c = self::mb_ord($uchr);
[252] Fix | Delete
[253] Fix | Delete
for ($j = 0; $j < $cnt; $j += 4) {
[254] Fix | Delete
if ($c >= $convmap[$j] && $c <= $convmap[$j + 1]) {
[255] Fix | Delete
$cOffset = ($c + $convmap[$j + 2]) & $convmap[$j + 3];
[256] Fix | Delete
$result .= $is_hex ? sprintf('&#x%X;', $cOffset) : '&#'.$cOffset.';';
[257] Fix | Delete
continue 2;
[258] Fix | Delete
}
[259] Fix | Delete
}
[260] Fix | Delete
$result .= $uchr;
[261] Fix | Delete
}
[262] Fix | Delete
[263] Fix | Delete
if (null === $encoding) {
[264] Fix | Delete
return $result;
[265] Fix | Delete
}
[266] Fix | Delete
[267] Fix | Delete
return iconv('UTF-8', $encoding.'//IGNORE', $result);
[268] Fix | Delete
}
[269] Fix | Delete
[270] Fix | Delete
public static function mb_convert_case($s, $mode, $encoding = null)
[271] Fix | Delete
{
[272] Fix | Delete
$s = (string) $s;
[273] Fix | Delete
if ('' === $s) {
[274] Fix | Delete
return '';
[275] Fix | Delete
}
[276] Fix | Delete
[277] Fix | Delete
$encoding = self::getEncoding($encoding);
[278] Fix | Delete
[279] Fix | Delete
if ('UTF-8' === $encoding) {
[280] Fix | Delete
$encoding = null;
[281] Fix | Delete
if (!preg_match('//u', $s)) {
[282] Fix | Delete
$s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
[283] Fix | Delete
}
[284] Fix | Delete
} else {
[285] Fix | Delete
$s = iconv($encoding, 'UTF-8//IGNORE', $s);
[286] Fix | Delete
}
[287] Fix | Delete
[288] Fix | Delete
if (MB_CASE_TITLE == $mode) {
[289] Fix | Delete
static $titleRegexp = null;
[290] Fix | Delete
if (null === $titleRegexp) {
[291] Fix | Delete
$titleRegexp = self::getData('titleCaseRegexp');
[292] Fix | Delete
}
[293] Fix | Delete
$s = preg_replace_callback($titleRegexp, array(__CLASS__, 'title_case'), $s);
[294] Fix | Delete
} else {
[295] Fix | Delete
if (MB_CASE_UPPER == $mode) {
[296] Fix | Delete
static $upper = null;
[297] Fix | Delete
if (null === $upper) {
[298] Fix | Delete
$upper = self::getData('upperCase');
[299] Fix | Delete
}
[300] Fix | Delete
$map = $upper;
[301] Fix | Delete
} else {
[302] Fix | Delete
if (self::MB_CASE_FOLD === $mode) {
[303] Fix | Delete
$s = str_replace(self::$caseFold[0], self::$caseFold[1], $s);
[304] Fix | Delete
}
[305] Fix | Delete
[306] Fix | Delete
static $lower = null;
[307] Fix | Delete
if (null === $lower) {
[308] Fix | Delete
$lower = self::getData('lowerCase');
[309] Fix | Delete
}
[310] Fix | Delete
$map = $lower;
[311] Fix | Delete
}
[312] Fix | Delete
[313] Fix | Delete
static $ulenMask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4);
[314] Fix | Delete
[315] Fix | Delete
$i = 0;
[316] Fix | Delete
$len = \strlen($s);
[317] Fix | Delete
[318] Fix | Delete
while ($i < $len) {
[319] Fix | Delete
$ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"];
[320] Fix | Delete
$uchr = substr($s, $i, $ulen);
[321] Fix | Delete
$i += $ulen;
[322] Fix | Delete
[323] Fix | Delete
if (isset($map[$uchr])) {
[324] Fix | Delete
$uchr = $map[$uchr];
[325] Fix | Delete
$nlen = \strlen($uchr);
[326] Fix | Delete
[327] Fix | Delete
if ($nlen == $ulen) {
[328] Fix | Delete
$nlen = $i;
[329] Fix | Delete
do {
[330] Fix | Delete
$s[--$nlen] = $uchr[--$ulen];
[331] Fix | Delete
} while ($ulen);
[332] Fix | Delete
} else {
[333] Fix | Delete
$s = substr_replace($s, $uchr, $i - $ulen, $ulen);
[334] Fix | Delete
$len += $nlen - $ulen;
[335] Fix | Delete
$i += $nlen - $ulen;
[336] Fix | Delete
}
[337] Fix | Delete
}
[338] Fix | Delete
}
[339] Fix | Delete
}
[340] Fix | Delete
[341] Fix | Delete
if (null === $encoding) {
[342] Fix | Delete
return $s;
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
return iconv('UTF-8', $encoding.'//IGNORE', $s);
[346] Fix | Delete
}
[347] Fix | Delete
[348] Fix | Delete
public static function mb_internal_encoding($encoding = null)
[349] Fix | Delete
{
[350] Fix | Delete
if (null === $encoding) {
[351] Fix | Delete
return self::$internalEncoding;
[352] Fix | Delete
}
[353] Fix | Delete
[354] Fix | Delete
$encoding = self::getEncoding($encoding);
[355] Fix | Delete
[356] Fix | Delete
if ('UTF-8' === $encoding || false !== @iconv($encoding, $encoding, ' ')) {
[357] Fix | Delete
self::$internalEncoding = $encoding;
[358] Fix | Delete
[359] Fix | Delete
return true;
[360] Fix | Delete
}
[361] Fix | Delete
[362] Fix | Delete
return false;
[363] Fix | Delete
}
[364] Fix | Delete
[365] Fix | Delete
public static function mb_language($lang = null)
[366] Fix | Delete
{
[367] Fix | Delete
if (null === $lang) {
[368] Fix | Delete
return self::$language;
[369] Fix | Delete
}
[370] Fix | Delete
[371] Fix | Delete
switch ($lang = strtolower($lang)) {
[372] Fix | Delete
case 'uni':
[373] Fix | Delete
case 'neutral':
[374] Fix | Delete
self::$language = $lang;
[375] Fix | Delete
[376] Fix | Delete
return true;
[377] Fix | Delete
}
[378] Fix | Delete
[379] Fix | Delete
return false;
[380] Fix | Delete
}
[381] Fix | Delete
[382] Fix | Delete
public static function mb_list_encodings()
[383] Fix | Delete
{
[384] Fix | Delete
return array('UTF-8');
[385] Fix | Delete
}
[386] Fix | Delete
[387] Fix | Delete
public static function mb_encoding_aliases($encoding)
[388] Fix | Delete
{
[389] Fix | Delete
switch (strtoupper($encoding)) {
[390] Fix | Delete
case 'UTF8':
[391] Fix | Delete
case 'UTF-8':
[392] Fix | Delete
return array('utf8');
[393] Fix | Delete
}
[394] Fix | Delete
[395] Fix | Delete
return false;
[396] Fix | Delete
}
[397] Fix | Delete
[398] Fix | Delete
public static function mb_check_encoding($var = null, $encoding = null)
[399] Fix | Delete
{
[400] Fix | Delete
if (null === $encoding) {
[401] Fix | Delete
if (null === $var) {
[402] Fix | Delete
return false;
[403] Fix | Delete
}
[404] Fix | Delete
$encoding = self::$internalEncoding;
[405] Fix | Delete
}
[406] Fix | Delete
[407] Fix | Delete
return self::mb_detect_encoding($var, array($encoding)) || false !== @iconv($encoding, $encoding, $var);
[408] Fix | Delete
}
[409] Fix | Delete
[410] Fix | Delete
public static function mb_detect_encoding($str, $encodingList = null, $strict = false)
[411] Fix | Delete
{
[412] Fix | Delete
if (null === $encodingList) {
[413] Fix | Delete
$encodingList = self::$encodingList;
[414] Fix | Delete
} else {
[415] Fix | Delete
if (!\is_array($encodingList)) {
[416] Fix | Delete
$encodingList = array_map('trim', explode(',', $encodingList));
[417] Fix | Delete
}
[418] Fix | Delete
$encodingList = array_map('strtoupper', $encodingList);
[419] Fix | Delete
}
[420] Fix | Delete
[421] Fix | Delete
foreach ($encodingList as $enc) {
[422] Fix | Delete
switch ($enc) {
[423] Fix | Delete
case 'ASCII':
[424] Fix | Delete
if (!preg_match('/[\x80-\xFF]/', $str)) {
[425] Fix | Delete
return $enc;
[426] Fix | Delete
}
[427] Fix | Delete
break;
[428] Fix | Delete
[429] Fix | Delete
case 'UTF8':
[430] Fix | Delete
case 'UTF-8':
[431] Fix | Delete
if (preg_match('//u', $str)) {
[432] Fix | Delete
return 'UTF-8';
[433] Fix | Delete
}
[434] Fix | Delete
break;
[435] Fix | Delete
[436] Fix | Delete
default:
[437] Fix | Delete
if (0 === strncmp($enc, 'ISO-8859-', 9)) {
[438] Fix | Delete
return $enc;
[439] Fix | Delete
}
[440] Fix | Delete
}
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
return false;
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
public static function mb_detect_order($encodingList = null)
[447] Fix | Delete
{
[448] Fix | Delete
if (null === $encodingList) {
[449] Fix | Delete
return self::$encodingList;
[450] Fix | Delete
}
[451] Fix | Delete
[452] Fix | Delete
if (!\is_array($encodingList)) {
[453] Fix | Delete
$encodingList = array_map('trim', explode(',', $encodingList));
[454] Fix | Delete
}
[455] Fix | Delete
$encodingList = array_map('strtoupper', $encodingList);
[456] Fix | Delete
[457] Fix | Delete
foreach ($encodingList as $enc) {
[458] Fix | Delete
switch ($enc) {
[459] Fix | Delete
default:
[460] Fix | Delete
if (strncmp($enc, 'ISO-8859-', 9)) {
[461] Fix | Delete
return false;
[462] Fix | Delete
}
[463] Fix | Delete
// no break
[464] Fix | Delete
case 'ASCII':
[465] Fix | Delete
case 'UTF8':
[466] Fix | Delete
case 'UTF-8':
[467] Fix | Delete
}
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
self::$encodingList = $encodingList;
[471] Fix | Delete
[472] Fix | Delete
return true;
[473] Fix | Delete
}
[474] Fix | Delete
[475] Fix | Delete
public static function mb_strlen($s, $encoding = null)
[476] Fix | Delete
{
[477] Fix | Delete
$encoding = self::getEncoding($encoding);
[478] Fix | Delete
if ('CP850' === $encoding || 'ASCII' === $encoding) {
[479] Fix | Delete
return \strlen($s);
[480] Fix | Delete
}
[481] Fix | Delete
[482] Fix | Delete
return @iconv_strlen($s, $encoding);
[483] Fix | Delete
}
[484] Fix | Delete
[485] Fix | Delete
public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null)
[486] Fix | Delete
{
[487] Fix | Delete
$encoding = self::getEncoding($encoding);
[488] Fix | Delete
if ('CP850' === $encoding || 'ASCII' === $encoding) {
[489] Fix | Delete
return strpos($haystack, $needle, $offset);
[490] Fix | Delete
}
[491] Fix | Delete
[492] Fix | Delete
$needle = (string) $needle;
[493] Fix | Delete
if ('' === $needle) {
[494] Fix | Delete
trigger_error(__METHOD__.': Empty delimiter', E_USER_WARNING);
[495] Fix | Delete
[496] Fix | Delete
return false;
[497] Fix | Delete
}
[498] Fix | Delete
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function