: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
$GetDataImageSize['height'] = $GetDataImageSize[0];
$GetDataImageSize['width'] = $GetDataImageSize[1];
return $GetDataImageSize;
if (function_exists('sys_get_temp_dir')) {
$tempdir = sys_get_temp_dir(); // https://github.com/JamesHeinrich/getID3/issues/52
// yes this is ugly, feel free to suggest a better way
if (include_once(dirname(__FILE__).'/getid3.php')) {
$getid3_temp = new getID3();
if ($getid3_temp_tempdir = $getid3_temp->tempdir) {
$tempdir = $getid3_temp_tempdir;
unset($getid3_temp, $getid3_temp_tempdir);
$GetDataImageSize = false;
if ($tempfilename = tempnam($tempdir, 'gI3')) {
if (is_writable($tempfilename) && is_file($tempfilename) && ($tmp = fopen($tempfilename, 'wb'))) {
$GetDataImageSize = @getimagesize($tempfilename, $imageinfo);
if (($GetDataImageSize === false) || !isset($GetDataImageSize[0]) || !isset($GetDataImageSize[1])) {
$GetDataImageSize['height'] = $GetDataImageSize[0];
$GetDataImageSize['width'] = $GetDataImageSize[1];
return $GetDataImageSize;
* @param string $mime_type
public static function ImageExtFromMime($mime_type) {
// temporary way, works OK for now, but should be reworked in the future
return str_replace(array('image/', 'x-', 'jpeg'), array('', '', 'jpg'), $mime_type);
* @param array $ThisFileInfo
* @param bool $option_tags_html default true (just as in the main getID3 class)
public static function CopyTagsToComments(&$ThisFileInfo, $option_tags_html=true) {
// Copy all entries from ['tags'] into common ['comments']
if (!empty($ThisFileInfo['tags'])) {
// Some tag types can only support limited character sets and may contain data in non-standard encoding (usually ID3v1)
// and/or poorly-transliterated tag values that are also in tag formats that do support full-range character sets
// To make the output more user-friendly, process the potentially-problematic tag formats last to enhance the chance that
// the first entries in [comments] are the most correct and the "bad" ones (if any) come later.
// https://github.com/JamesHeinrich/getID3/issues/338
$processLastTagTypes = array('id3v1','riff');
foreach ($processLastTagTypes as $processLastTagType) {
if (isset($ThisFileInfo['tags'][$processLastTagType])) {
// bubble ID3v1 to the end, if present to aid in detecting bad ID3v1 encodings
$temp = $ThisFileInfo['tags'][$processLastTagType];
unset($ThisFileInfo['tags'][$processLastTagType]);
$ThisFileInfo['tags'][$processLastTagType] = $temp;
foreach ($ThisFileInfo['tags'] as $tagtype => $tagarray) {
foreach ($tagarray as $tagname => $tagdata) {
foreach ($tagdata as $key => $value) {
if (empty($ThisFileInfo['comments'][$tagname])) {
// fall through and append value
} elseif ($tagtype == 'id3v1') {
$newvaluelength = strlen(trim($value));
foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
$oldvaluelength = strlen(trim($existingvalue));
if (($newvaluelength <= $oldvaluelength) && (substr($existingvalue, 0, $newvaluelength) == trim($value))) {
// new value is identical but shorter-than (or equal-length to) one already in comments - skip
if (function_exists('mb_convert_encoding')) {
if (trim($value) == trim(substr(mb_convert_encoding($existingvalue, $ThisFileInfo['id3v1']['encoding'], $ThisFileInfo['encoding']), 0, 30))) {
// value stored in ID3v1 appears to be probably the multibyte value transliterated (badly) into ISO-8859-1 in ID3v1.
// As an example, Foobar2000 will do this if you tag a file with Chinese or Arabic or Cyrillic or something that doesn't fit into ISO-8859-1 the ID3v1 will consist of mostly "?" characters, one per multibyte unrepresentable character
} elseif (!is_array($value)) {
$newvaluelength = strlen(trim($value));
$newvaluelengthMB = mb_strlen(trim($value));
foreach ($ThisFileInfo['comments'][$tagname] as $existingkey => $existingvalue) {
$oldvaluelength = strlen(trim($existingvalue));
$oldvaluelengthMB = mb_strlen(trim($existingvalue));
if (($newvaluelengthMB == $oldvaluelengthMB) && ($existingvalue == getid3_lib::iconv_fallback('UTF-8', 'ASCII', $value))) {
// https://github.com/JamesHeinrich/getID3/issues/338
// check for tags containing extended characters that may have been forced into limited-character storage (e.g. UTF8 values into ASCII)
// which will usually display unrepresentable characters as "?"
$ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);
if ((strlen($existingvalue) > 10) && ($newvaluelength > $oldvaluelength) && (substr(trim($value), 0, strlen($existingvalue)) == $existingvalue)) {
$ThisFileInfo['comments'][$tagname][$existingkey] = trim($value);
if (is_array($value) || empty($ThisFileInfo['comments'][$tagname]) || !in_array(trim($value), $ThisFileInfo['comments'][$tagname])) {
$value = (is_string($value) ? trim($value) : $value);
if (!is_int($key) && !ctype_digit($key)) {
$ThisFileInfo['comments'][$tagname][$key] = $value;
if (!isset($ThisFileInfo['comments'][$tagname])) {
$ThisFileInfo['comments'][$tagname] = array($value);
$ThisFileInfo['comments'][$tagname][] = $value;
// attempt to standardize spelling of returned keys
if (!empty($ThisFileInfo['comments'])) {
$StandardizeFieldNames = array(
'tracknumber' => 'track_number',
'track' => 'track_number',
foreach ($StandardizeFieldNames as $badkey => $goodkey) {
if (array_key_exists($badkey, $ThisFileInfo['comments']) && !array_key_exists($goodkey, $ThisFileInfo['comments'])) {
$ThisFileInfo['comments'][$goodkey] = $ThisFileInfo['comments'][$badkey];
unset($ThisFileInfo['comments'][$badkey]);
// Copy ['comments'] to ['comments_html']
if (!empty($ThisFileInfo['comments'])) {
foreach ($ThisFileInfo['comments'] as $field => $values) {
if ($field == 'picture') {
// pictures can take up a lot of space, and we don't need multiple copies of them
// let there be a single copy in [comments][picture], and not elsewhere
foreach ($values as $index => $value) {
$ThisFileInfo['comments_html'][$field][$index] = $value;
$ThisFileInfo['comments_html'][$field][$index] = str_replace('�', '', self::MultiByteCharString2HTML($value, $ThisFileInfo['encoding']));
public static function EmbeddedLookup($key, $begin, $end, $file, $name) {
if (isset($cache[$file][$name])) {
return (isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : '');
$keylength = strlen($key);
$line_count = $end - $begin - 7;
for ($i = 0; $i < ($begin + 3); $i++) {
while (0 < $line_count--) {
$line = ltrim(fgets($fp, 1024), "\t ");
// METHOD A: only cache the matching key - less memory but slower on next lookup of not-previously-looked-up key
//$keycheck = substr($line, 0, $keylength);
//if ($key == $keycheck) {
// $cache[$file][$name][$keycheck] = substr($line, $keylength + 1);
// METHOD B: cache all keys in this lookup - more memory but faster on next lookup of not-previously-looked-up key
//$cache[$file][$name][substr($line, 0, $keylength)] = trim(substr($line, $keylength + 1));
$explodedLine = explode("\t", $line, 2);
$ThisKey = (isset($explodedLine[0]) ? $explodedLine[0] : '');
$ThisValue = (isset($explodedLine[1]) ? $explodedLine[1] : '');
$cache[$file][$name][$ThisKey] = trim($ThisValue);
return (isset($cache[$file][$name][$key]) ? $cache[$file][$name][$key] : '');
* @param string $filename
* @param string $sourcefile
* @param bool $DieOnFailure
public static function IncludeDependency($filename, $sourcefile, $DieOnFailure=false) {
global $GETID3_ERRORARRAY;
if (file_exists($filename)) {
if (include_once($filename)) {
$diemessage = basename($sourcefile).' depends on '.$filename.', which has errors';
$diemessage = basename($sourcefile).' depends on '.$filename.', which is missing';
throw new Exception($diemessage);
$GETID3_ERRORARRAY[] = $diemessage;
public static function trimNullByte($string) {
return trim($string, "\x00");
public static function getFileSizeSyscall($path) {
if (GETID3_OS_ISWINDOWS) {
if (class_exists('COM')) { // From PHP 5.3.15 and 5.4.5, COM and DOTNET is no longer built into the php core.you have to add COM support in php.ini:
$filesystem = new COM('Scripting.FileSystemObject');
$file = $filesystem->GetFile($path);
$filesize = $file->Size();
unset($filesystem, $file);
$commandline = 'for %I in ('.escapeshellarg($path).') do @echo %~zI';
$commandline = 'ls -l '.escapeshellarg($path).' | awk \'{print $5}\'';
if (isset($commandline)) {
$output = trim(`$commandline`);
if (ctype_digit($output)) {
$filesize = (float) $output;
* @param string $filename
public static function truepath($filename) {
// 2017-11-08: this could use some improvement, patches welcome
if (preg_match('#^(\\\\\\\\|//)[a-z0-9]#i', $filename, $matches)) {
// PHP's built-in realpath function does not work on UNC Windows shares
foreach (explode('/', str_replace('\\', '/', $filename)) as $part) {
// cannot step above this level, already at top level
return implode(DIRECTORY_SEPARATOR, $goodpath);
return realpath($filename);
* Workaround for Bug #37268 (https://bugs.php.net/bug.php?id=37268)
* @param string $path A path.
* @param string $suffix If the name component ends in suffix this will also be cut off.
public static function mb_basename($path, $suffix = '') {
$splited = preg_split('#/#', rtrim($path, '/ '));
return substr(basename('X'.$splited[count($splited) - 1], $suffix), 1);