: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$newcharstring .= "\xFE\xFF";
$stringlength = strlen($string);
while ($offset < $stringlength) {
if ((ord($string[$offset]) | 0x07) == 0xF7) {
// 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
$charval = ((ord($string[($offset + 0)]) & 0x07) << 18) &
((ord($string[($offset + 1)]) & 0x3F) << 12) &
((ord($string[($offset + 2)]) & 0x3F) << 6) &
(ord($string[($offset + 3)]) & 0x3F);
} elseif ((ord($string[$offset]) | 0x0F) == 0xEF) {
// 1110bbbb 10bbbbbb 10bbbbbb
$charval = ((ord($string[($offset + 0)]) & 0x0F) << 12) &
((ord($string[($offset + 1)]) & 0x3F) << 6) &
(ord($string[($offset + 2)]) & 0x3F);
} elseif ((ord($string[$offset]) | 0x1F) == 0xDF) {
$charval = ((ord($string[($offset + 0)]) & 0x1F) << 6) &
(ord($string[($offset + 1)]) & 0x3F);
} elseif ((ord($string[$offset]) | 0x7F) == 0x7F) {
$charval = ord($string[$offset]);
// error? throw some kind of warning here?
if ($charval !== false) {
$newcharstring .= (($charval < 65536) ? self::BigEndian2String($charval, 2) : "\x00".'?');
public static function iconv_fallback_utf8_utf16le($string, $bom=false) {
$newcharstring .= "\xFF\xFE";
$stringlength = strlen($string);
while ($offset < $stringlength) {
if ((ord($string[$offset]) | 0x07) == 0xF7) {
// 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
$charval = ((ord($string[($offset + 0)]) & 0x07) << 18) &
((ord($string[($offset + 1)]) & 0x3F) << 12) &
((ord($string[($offset + 2)]) & 0x3F) << 6) &
(ord($string[($offset + 3)]) & 0x3F);
} elseif ((ord($string[$offset]) | 0x0F) == 0xEF) {
// 1110bbbb 10bbbbbb 10bbbbbb
$charval = ((ord($string[($offset + 0)]) & 0x0F) << 12) &
((ord($string[($offset + 1)]) & 0x3F) << 6) &
(ord($string[($offset + 2)]) & 0x3F);
} elseif ((ord($string[$offset]) | 0x1F) == 0xDF) {
$charval = ((ord($string[($offset + 0)]) & 0x1F) << 6) &
(ord($string[($offset + 1)]) & 0x3F);
} elseif ((ord($string[$offset]) | 0x7F) == 0x7F) {
$charval = ord($string[$offset]);
// error? maybe throw some warning here?
if ($charval !== false) {
$newcharstring .= (($charval < 65536) ? self::LittleEndian2String($charval, 2) : '?'."\x00");
* UTF-8 => UTF-16LE (BOM)
public static function iconv_fallback_utf8_utf16($string) {
return self::iconv_fallback_utf8_utf16le($string, true);
public static function iconv_fallback_utf16be_utf8($string) {
if (substr($string, 0, 2) == "\xFE\xFF") {
$string = substr($string, 2);
for ($i = 0; $i < strlen($string); $i += 2) {
$charval = self::BigEndian2Int(substr($string, $i, 2));
$newcharstring .= self::iconv_fallback_int_utf8($charval);
public static function iconv_fallback_utf16le_utf8($string) {
if (substr($string, 0, 2) == "\xFF\xFE") {
$string = substr($string, 2);
for ($i = 0; $i < strlen($string); $i += 2) {
$charval = self::LittleEndian2Int(substr($string, $i, 2));
$newcharstring .= self::iconv_fallback_int_utf8($charval);
public static function iconv_fallback_utf16be_iso88591($string) {
if (substr($string, 0, 2) == "\xFE\xFF") {
$string = substr($string, 2);
for ($i = 0; $i < strlen($string); $i += 2) {
$charval = self::BigEndian2Int(substr($string, $i, 2));
$newcharstring .= (($charval < 256) ? chr($charval) : '?');
public static function iconv_fallback_utf16le_iso88591($string) {
if (substr($string, 0, 2) == "\xFF\xFE") {
$string = substr($string, 2);
for ($i = 0; $i < strlen($string); $i += 2) {
$charval = self::LittleEndian2Int(substr($string, $i, 2));
$newcharstring .= (($charval < 256) ? chr($charval) : '?');
* UTF-16 (BOM) => ISO-8859-1
public static function iconv_fallback_utf16_iso88591($string) {
$bom = substr($string, 0, 2);
if ($bom == "\xFE\xFF") {
return self::iconv_fallback_utf16be_iso88591(substr($string, 2));
} elseif ($bom == "\xFF\xFE") {
return self::iconv_fallback_utf16le_iso88591(substr($string, 2));
public static function iconv_fallback_utf16_utf8($string) {
$bom = substr($string, 0, 2);
if ($bom == "\xFE\xFF") {
return self::iconv_fallback_utf16be_utf8(substr($string, 2));
} elseif ($bom == "\xFF\xFE") {
return self::iconv_fallback_utf16le_utf8(substr($string, 2));
* @param string $in_charset
* @param string $out_charset
public static function iconv_fallback($in_charset, $out_charset, $string) {
if ($in_charset == $out_charset) {
// mb_convert_encoding() available
if (function_exists('mb_convert_encoding')) {
if ((strtoupper($in_charset) == 'UTF-16') && (substr($string, 0, 2) != "\xFE\xFF") && (substr($string, 0, 2) != "\xFF\xFE")) {
// if BOM missing, mb_convert_encoding will mishandle the conversion, assume UTF-16BE and prepend appropriate BOM
$string = "\xFF\xFE".$string;
if ((strtoupper($in_charset) == 'UTF-16') && (strtoupper($out_charset) == 'UTF-8')) {
if (($string == "\xFF\xFE") || ($string == "\xFE\xFF")) {
// if string consists of only BOM, mb_convert_encoding will return the BOM unmodified
if ($converted_string = @mb_convert_encoding($string, $out_charset, $in_charset)) {
$converted_string = rtrim($converted_string, "\x00");
return $converted_string;
} elseif (function_exists('iconv')) {
if ($converted_string = @iconv($in_charset, $out_charset.'//TRANSLIT', $string)) {
$converted_string = rtrim($converted_string, "\x00");
return $converted_string;
// iconv() may sometimes fail with "illegal character in input string" error message
// and return an empty string, but returning the unconverted string is more useful
// neither mb_convert_encoding or iconv() is available
static $ConversionFunctionList = array();
if (empty($ConversionFunctionList)) {
$ConversionFunctionList['ISO-8859-1']['UTF-8'] = 'iconv_fallback_iso88591_utf8';
$ConversionFunctionList['ISO-8859-1']['UTF-16'] = 'iconv_fallback_iso88591_utf16';
$ConversionFunctionList['ISO-8859-1']['UTF-16BE'] = 'iconv_fallback_iso88591_utf16be';
$ConversionFunctionList['ISO-8859-1']['UTF-16LE'] = 'iconv_fallback_iso88591_utf16le';
$ConversionFunctionList['UTF-8']['ISO-8859-1'] = 'iconv_fallback_utf8_iso88591';
$ConversionFunctionList['UTF-8']['UTF-16'] = 'iconv_fallback_utf8_utf16';
$ConversionFunctionList['UTF-8']['UTF-16BE'] = 'iconv_fallback_utf8_utf16be';
$ConversionFunctionList['UTF-8']['UTF-16LE'] = 'iconv_fallback_utf8_utf16le';
$ConversionFunctionList['UTF-16']['ISO-8859-1'] = 'iconv_fallback_utf16_iso88591';
$ConversionFunctionList['UTF-16']['UTF-8'] = 'iconv_fallback_utf16_utf8';
$ConversionFunctionList['UTF-16LE']['ISO-8859-1'] = 'iconv_fallback_utf16le_iso88591';
$ConversionFunctionList['UTF-16LE']['UTF-8'] = 'iconv_fallback_utf16le_utf8';
$ConversionFunctionList['UTF-16BE']['ISO-8859-1'] = 'iconv_fallback_utf16be_iso88591';
$ConversionFunctionList['UTF-16BE']['UTF-8'] = 'iconv_fallback_utf16be_utf8';
if (isset($ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)])) {
$ConversionFunction = $ConversionFunctionList[strtoupper($in_charset)][strtoupper($out_charset)];
return self::$ConversionFunction($string);
throw new Exception('PHP does not has mb_convert_encoding() or iconv() support - cannot convert from '.$in_charset.' to '.$out_charset);
public static function recursiveMultiByteCharString2HTML($data, $charset='ISO-8859-1') {
return self::MultiByteCharString2HTML($data, $charset);
} elseif (is_array($data)) {
foreach ($data as $key => $value) {
$return_data[$key] = self::recursiveMultiByteCharString2HTML($value, $charset);
// integer, float, objects, resources, etc
* @param string|int|float $string
public static function MultiByteCharString2HTML($string, $charset='ISO-8859-1') {
$string = (string) $string; // in case trying to pass a numeric (float, int) string, would otherwise return an empty string
switch (strtolower($charset)) {
$HTMLstring = htmlentities($string, ENT_COMPAT, $charset);
$strlen = strlen($string);
for ($i = 0; $i < $strlen; $i++) {
$char_ord_val = ord($string[$i]);
if ($char_ord_val < 0x80) {
$charval = $char_ord_val;
} elseif ((($char_ord_val & 0xF0) >> 4) == 0x0F && $i+3 < $strlen) {
$charval = (($char_ord_val & 0x07) << 18);
$charval += ((ord($string[++$i]) & 0x3F) << 12);
$charval += ((ord($string[++$i]) & 0x3F) << 6);
$charval += (ord($string[++$i]) & 0x3F);
} elseif ((($char_ord_val & 0xE0) >> 5) == 0x07 && $i+2 < $strlen) {
$charval = (($char_ord_val & 0x0F) << 12);
$charval += ((ord($string[++$i]) & 0x3F) << 6);
$charval += (ord($string[++$i]) & 0x3F);
} elseif ((($char_ord_val & 0xC0) >> 6) == 0x03 && $i+1 < $strlen) {
$charval = (($char_ord_val & 0x1F) << 6);
$charval += (ord($string[++$i]) & 0x3F);
if (($charval >= 32) && ($charval <= 127)) {
$HTMLstring .= htmlentities(chr($charval));
$HTMLstring .= '&#'.$charval.';';
for ($i = 0; $i < strlen($string); $i += 2) {
$charval = self::LittleEndian2Int(substr($string, $i, 2));
if (($charval >= 32) && ($charval <= 127)) {
$HTMLstring .= chr($charval);
$HTMLstring .= '&#'.$charval.';';
for ($i = 0; $i < strlen($string); $i += 2) {
$charval = self::BigEndian2Int(substr($string, $i, 2));
if (($charval >= 32) && ($charval <= 127)) {
$HTMLstring .= chr($charval);
$HTMLstring .= '&#'.$charval.';';
$HTMLstring = 'ERROR: Character set "'.$charset.'" not supported in MultiByteCharString2HTML()';
public static function RGADnameLookup($namecode) {
static $RGADname = array();
$RGADname[0] = 'not set';
$RGADname[1] = 'Track Gain Adjustment';
$RGADname[2] = 'Album Gain Adjustment';
return (isset($RGADname[$namecode]) ? $RGADname[$namecode] : '');
* @param int $originatorcode
public static function RGADoriginatorLookup($originatorcode) {
static $RGADoriginator = array();
if (empty($RGADoriginator)) {
$RGADoriginator[0] = 'unspecified';
$RGADoriginator[1] = 'pre-set by artist/producer/mastering engineer';
$RGADoriginator[2] = 'set by user';
$RGADoriginator[3] = 'determined automatically';
return (isset($RGADoriginator[$originatorcode]) ? $RGADoriginator[$originatorcode] : '');
* @param int $rawadjustment
public static function RGADadjustmentLookup($rawadjustment, $signbit) {
$adjustment = (float) $rawadjustment / 10;
* @param int $originatorcode
public static function RGADgainString($namecode, $originatorcode, $replaygain) {
$storedreplaygain = intval(round($replaygain * 10));
$gainstring = str_pad(decbin($namecode), 3, '0', STR_PAD_LEFT);
$gainstring .= str_pad(decbin($originatorcode), 3, '0', STR_PAD_LEFT);
$gainstring .= str_pad(decbin($storedreplaygain), 9, '0', STR_PAD_LEFT);
* @param float $amplitude
public static function RGADamplitude2dB($amplitude) {
return 20 * log10($amplitude);
* @param array $imageinfo
public static function GetDataImageSize($imgData, &$imageinfo=array()) {
if (PHP_VERSION_ID >= 50400) {
$GetDataImageSize = @getimagesizefromstring($imgData, $imageinfo);
if ($GetDataImageSize === false || !isset($GetDataImageSize[0], $GetDataImageSize[1])) {