: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
public static function LittleEndian2String($number, $minbytes=1, $synchsafe=false) {
$intstring = $intstring.chr($number & 127);
$intstring = $intstring.chr($number & 255);
return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT);
public static function array_merge_clobber($array1, $array2) {
// written by kcØhireability*com
// taken from http://www.php.net/manual/en/function.array-merge-recursive.php
if (!is_array($array1) || !is_array($array2)) {
foreach ($array2 as $key => $val) {
if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) {
$newarray[$key] = self::array_merge_clobber($newarray[$key], $val);
public static function array_merge_noclobber($array1, $array2) {
if (!is_array($array1) || !is_array($array2)) {
foreach ($array2 as $key => $val) {
if (is_array($val) && isset($newarray[$key]) && is_array($newarray[$key])) {
$newarray[$key] = self::array_merge_noclobber($newarray[$key], $val);
} elseif (!isset($newarray[$key])) {
* @return array|false|null
public static function flipped_array_merge_noclobber($array1, $array2) {
if (!is_array($array1) || !is_array($array2)) {
# naturally, this only works non-recursively
$newarray = array_flip($array1);
foreach (array_flip($array2) as $key => $val) {
if (!isset($newarray[$key])) {
$newarray[$key] = count($newarray);
return array_flip($newarray);
public static function ksort_recursive(&$theArray) {
foreach ($theArray as $key => $value) {
self::ksort_recursive($theArray[$key]);
* @param string $filename
* @param int $numextensions
public static function fileextension($filename, $numextensions=1) {
if (strstr($filename, '.')) {
$reversedfilename = strrev($filename);
for ($i = 0; $i < $numextensions; $i++) {
$offset = strpos($reversedfilename, '.', $offset + 1);
return strrev(substr($reversedfilename, 0, $offset));
public static function PlaytimeString($seconds) {
$sign = (($seconds < 0) ? '-' : '');
$seconds = round(abs($seconds));
$H = (int) floor( $seconds / 3600);
$M = (int) floor(($seconds - (3600 * $H) ) / 60);
$S = (int) round( $seconds - (3600 * $H) - (60 * $M) );
return $sign.($H ? $H.':' : '').($H ? str_pad($M, 2, '0', STR_PAD_LEFT) : intval($M)).':'.str_pad($S, 2, 0, STR_PAD_LEFT);
public static function DateMac2Unix($macdate) {
// Macintosh timestamp: seconds since 00:00h January 1, 1904
// UNIX timestamp: seconds since 00:00h January 1, 1970
return self::CastAsInt($macdate - 2082844800);
public static function FixedPoint8_8($rawdata) {
return self::BigEndian2Int(substr($rawdata, 0, 1)) + (float) (self::BigEndian2Int(substr($rawdata, 1, 1)) / pow(2, 8));
public static function FixedPoint16_16($rawdata) {
return self::BigEndian2Int(substr($rawdata, 0, 2)) + (float) (self::BigEndian2Int(substr($rawdata, 2, 2)) / pow(2, 16));
public static function FixedPoint2_30($rawdata) {
$binarystring = self::BigEndian2Bin($rawdata);
return self::Bin2Dec(substr($binarystring, 0, 2)) + (float) (self::Bin2Dec(substr($binarystring, 2, 30)) / pow(2, 30));
* @param string $ArrayPath
* @param string $Separator
public static function CreateDeepArray($ArrayPath, $Separator, $Value) {
// assigns $Value to a nested array path:
// $foo = self::CreateDeepArray('/path/to/my', '/', 'file.txt')
// $foo = array('path'=>array('to'=>'array('my'=>array('file.txt'))));
// $foo['path']['to']['my'] = 'file.txt';
$ArrayPath = ltrim($ArrayPath, $Separator);
$ReturnedArray = array();
if (($pos = strpos($ArrayPath, $Separator)) !== false) {
$ReturnedArray[substr($ArrayPath, 0, $pos)] = self::CreateDeepArray(substr($ArrayPath, $pos + 1), $Separator, $Value);
$ReturnedArray[$ArrayPath] = $Value;
* @param array $arraydata
public static function array_max($arraydata, $returnkey=false) {
foreach ($arraydata as $key => $value) {
if (($maxvalue === false) || ($value > $maxvalue)) {
return ($returnkey ? $maxkey : $maxvalue);
* @param array $arraydata
public static function array_min($arraydata, $returnkey=false) {
foreach ($arraydata as $key => $value) {
if (($minvalue === false) || ($value < $minvalue)) {
return ($returnkey ? $minkey : $minvalue);
* @param string $XMLstring
public static function XML2array($XMLstring) {
if (function_exists('simplexml_load_string') && function_exists('libxml_disable_entity_loader')) {
// http://websec.io/2012/08/27/Preventing-XEE-in-PHP.html
// https://core.trac.wordpress.org/changeset/29378
// This function has been deprecated in PHP 8.0 because in libxml 2.9.0, external entity loading is
// disabled by default, but is still needed when LIBXML_NOENT is used.
$loader = @libxml_disable_entity_loader(true);
$XMLobject = simplexml_load_string($XMLstring, 'SimpleXMLElement', GETID3_LIBXML_OPTIONS);
$return = self::SimpleXMLelement2array($XMLobject);
@libxml_disable_entity_loader($loader);
* @param SimpleXMLElement|array|mixed $XMLobject
public static function SimpleXMLelement2array($XMLobject) {
if (!is_object($XMLobject) && !is_array($XMLobject)) {
$XMLarray = $XMLobject instanceof SimpleXMLElement ? get_object_vars($XMLobject) : $XMLobject;
foreach ($XMLarray as $key => $value) {
$XMLarray[$key] = self::SimpleXMLelement2array($value);
* Returns checksum for a file from starting position to absolute end position.
* @param string $algorithm
* @throws getid3_exception
public static function hash_data($file, $offset, $end, $algorithm) {
if (!self::intValueSupported($end)) {
if (!in_array($algorithm, array('md5', 'sha1'))) {
throw new getid3_exception('Invalid algorithm ('.$algorithm.') in self::hash_data()');
$fp = fopen($file, 'rb');
$ctx = hash_init($algorithm);
$buffer = fread($fp, min($size, getID3::FREAD_BUFFER_SIZE));
hash_update($ctx, $buffer);
$size -= getID3::FREAD_BUFFER_SIZE;
$hash = hash_final($ctx);
* @param string $filename_source
* @param string $filename_dest
* @deprecated Unused, may be removed in future versions of getID3
public static function CopyFileParts($filename_source, $filename_dest, $offset, $length) {
if (!self::intValueSupported($offset + $length)) {
throw new Exception('cannot copy file portion, it extends beyond the '.round(PHP_INT_MAX / 1073741824).'GB limit');
if (is_readable($filename_source) && is_file($filename_source) && ($fp_src = fopen($filename_source, 'rb'))) {
if (($fp_dest = fopen($filename_dest, 'wb'))) {
if (fseek($fp_src, $offset) == 0) {
$byteslefttowrite = $length;
while (($byteslefttowrite > 0) && ($buffer = fread($fp_src, min($byteslefttowrite, getID3::FREAD_BUFFER_SIZE)))) {
$byteswritten = fwrite($fp_dest, $buffer, $byteslefttowrite);
$byteslefttowrite -= $byteswritten;
throw new Exception('failed to seek to offset '.$offset.' in '.$filename_source);
throw new Exception('failed to create file for writing '.$filename_dest);
throw new Exception('failed to open file for reading '.$filename_source);
public static function iconv_fallback_int_utf8($charval) {
$newcharstring = chr($charval);
} elseif ($charval < 2048) {
$newcharstring = chr(($charval >> 6) | 0xC0);
$newcharstring .= chr(($charval & 0x3F) | 0x80);
} elseif ($charval < 65536) {
// 1110bbbb 10bbbbbb 10bbbbbb
$newcharstring = chr(($charval >> 12) | 0xE0);
$newcharstring .= chr(($charval >> 6) | 0xC0);
$newcharstring .= chr(($charval & 0x3F) | 0x80);
// 11110bbb 10bbbbbb 10bbbbbb 10bbbbbb
$newcharstring = chr(($charval >> 18) | 0xF0);
$newcharstring .= chr(($charval >> 12) | 0xC0);
$newcharstring .= chr(($charval >> 6) | 0xC0);
$newcharstring .= chr(($charval & 0x3F) | 0x80);
public static function iconv_fallback_iso88591_utf8($string, $bom=false) {
$newcharstring .= "\xEF\xBB\xBF";
for ($i = 0; $i < strlen($string); $i++) {
$charval = ord($string[$i]);
$newcharstring .= self::iconv_fallback_int_utf8($charval);
public static function iconv_fallback_iso88591_utf16be($string, $bom=false) {
$newcharstring .= "\xFE\xFF";
for ($i = 0; $i < strlen($string); $i++) {
$newcharstring .= "\x00".$string[$i];
public static function iconv_fallback_iso88591_utf16le($string, $bom=false) {
$newcharstring .= "\xFF\xFE";
for ($i = 0; $i < strlen($string); $i++) {
$newcharstring .= $string[$i]."\x00";
* ISO-8859-1 => UTF-16LE (BOM)
public static function iconv_fallback_iso88591_utf16($string) {
return self::iconv_fallback_iso88591_utf16le($string, true);
public static function iconv_fallback_utf8_iso88591($string) {
$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 < 256) ? chr($charval) : '?');
public static function iconv_fallback_utf8_utf16be($string, $bom=false) {