Edit File by line
/home/zeestwma/ceyloniy.../wp-inclu.../ID3
File: getid3.lib.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/////////////////////////////////////////////////////////////////
[2] Fix | Delete
/// getID3() by James Heinrich <info@getid3.org> //
[3] Fix | Delete
// available at https://github.com/JamesHeinrich/getID3 //
[4] Fix | Delete
// or https://www.getid3.org //
[5] Fix | Delete
// or http://getid3.sourceforge.net //
[6] Fix | Delete
// //
[7] Fix | Delete
// getid3.lib.php - part of getID3() //
[8] Fix | Delete
// see readme.txt for more details //
[9] Fix | Delete
// ///
[10] Fix | Delete
/////////////////////////////////////////////////////////////////
[11] Fix | Delete
[12] Fix | Delete
if (!defined('GETID3_LIBXML_OPTIONS') && defined('LIBXML_VERSION')) {
[13] Fix | Delete
if (LIBXML_VERSION >= 20621) {
[14] Fix | Delete
define('GETID3_LIBXML_OPTIONS', LIBXML_NOENT | LIBXML_NONET | LIBXML_NOWARNING | LIBXML_COMPACT);
[15] Fix | Delete
} else {
[16] Fix | Delete
define('GETID3_LIBXML_OPTIONS', LIBXML_NOENT | LIBXML_NONET | LIBXML_NOWARNING);
[17] Fix | Delete
}
[18] Fix | Delete
}
[19] Fix | Delete
[20] Fix | Delete
class getid3_lib
[21] Fix | Delete
{
[22] Fix | Delete
/**
[23] Fix | Delete
* @param string $string
[24] Fix | Delete
* @param bool $hex
[25] Fix | Delete
* @param bool $spaces
[26] Fix | Delete
* @param string|bool $htmlencoding
[27] Fix | Delete
*
[28] Fix | Delete
* @return string
[29] Fix | Delete
*/
[30] Fix | Delete
public static function PrintHexBytes($string, $hex=true, $spaces=true, $htmlencoding='UTF-8') {
[31] Fix | Delete
$returnstring = '';
[32] Fix | Delete
for ($i = 0; $i < strlen($string); $i++) {
[33] Fix | Delete
if ($hex) {
[34] Fix | Delete
$returnstring .= str_pad(dechex(ord($string[$i])), 2, '0', STR_PAD_LEFT);
[35] Fix | Delete
} else {
[36] Fix | Delete
$returnstring .= ' '.(preg_match("#[\x20-\x7E]#", $string[$i]) ? $string[$i] : 'ยค');
[37] Fix | Delete
}
[38] Fix | Delete
if ($spaces) {
[39] Fix | Delete
$returnstring .= ' ';
[40] Fix | Delete
}
[41] Fix | Delete
}
[42] Fix | Delete
if (!empty($htmlencoding)) {
[43] Fix | Delete
if ($htmlencoding === true) {
[44] Fix | Delete
$htmlencoding = 'UTF-8'; // prior to getID3 v1.9.0 the function's 4th parameter was boolean
[45] Fix | Delete
}
[46] Fix | Delete
$returnstring = htmlentities($returnstring, ENT_QUOTES, $htmlencoding);
[47] Fix | Delete
}
[48] Fix | Delete
return $returnstring;
[49] Fix | Delete
}
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* Truncates a floating-point number at the decimal point.
[53] Fix | Delete
*
[54] Fix | Delete
* @param float $floatnumber
[55] Fix | Delete
*
[56] Fix | Delete
* @return float|int returns int (if possible, otherwise float)
[57] Fix | Delete
*/
[58] Fix | Delete
public static function trunc($floatnumber) {
[59] Fix | Delete
if ($floatnumber >= 1) {
[60] Fix | Delete
$truncatednumber = floor($floatnumber);
[61] Fix | Delete
} elseif ($floatnumber <= -1) {
[62] Fix | Delete
$truncatednumber = ceil($floatnumber);
[63] Fix | Delete
} else {
[64] Fix | Delete
$truncatednumber = 0;
[65] Fix | Delete
}
[66] Fix | Delete
if (self::intValueSupported($truncatednumber)) {
[67] Fix | Delete
$truncatednumber = (int) $truncatednumber;
[68] Fix | Delete
}
[69] Fix | Delete
return $truncatednumber;
[70] Fix | Delete
}
[71] Fix | Delete
[72] Fix | Delete
/**
[73] Fix | Delete
* @param int|null $variable
[74] Fix | Delete
* @param-out int $variable
[75] Fix | Delete
* @param int $increment
[76] Fix | Delete
*
[77] Fix | Delete
* @return bool
[78] Fix | Delete
*/
[79] Fix | Delete
public static function safe_inc(&$variable, $increment=1) {
[80] Fix | Delete
if (isset($variable)) {
[81] Fix | Delete
$variable += $increment;
[82] Fix | Delete
} else {
[83] Fix | Delete
$variable = $increment;
[84] Fix | Delete
}
[85] Fix | Delete
return true;
[86] Fix | Delete
}
[87] Fix | Delete
[88] Fix | Delete
/**
[89] Fix | Delete
* @param int|float $floatnum
[90] Fix | Delete
*
[91] Fix | Delete
* @return int|float
[92] Fix | Delete
*/
[93] Fix | Delete
public static function CastAsInt($floatnum) {
[94] Fix | Delete
// convert to float if not already
[95] Fix | Delete
$floatnum = (float) $floatnum;
[96] Fix | Delete
[97] Fix | Delete
// convert a float to type int, only if possible
[98] Fix | Delete
if (self::trunc($floatnum) == $floatnum) {
[99] Fix | Delete
// it's not floating point
[100] Fix | Delete
if (self::intValueSupported($floatnum)) {
[101] Fix | Delete
// it's within int range
[102] Fix | Delete
$floatnum = (int) $floatnum;
[103] Fix | Delete
}
[104] Fix | Delete
}
[105] Fix | Delete
return $floatnum;
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
/**
[109] Fix | Delete
* @param int $num
[110] Fix | Delete
*
[111] Fix | Delete
* @return bool
[112] Fix | Delete
*/
[113] Fix | Delete
public static function intValueSupported($num) {
[114] Fix | Delete
// check if integers are 64-bit
[115] Fix | Delete
static $hasINT64 = null;
[116] Fix | Delete
if ($hasINT64 === null) { // 10x faster than is_null()
[117] Fix | Delete
/** @var int|float|object $bigInt */
[118] Fix | Delete
$bigInt = pow(2, 31);
[119] Fix | Delete
$hasINT64 = is_int($bigInt); // 32-bit int are limited to (2^31)-1
[120] Fix | Delete
if (!$hasINT64 && !defined('PHP_INT_MIN')) {
[121] Fix | Delete
define('PHP_INT_MIN', ~PHP_INT_MAX);
[122] Fix | Delete
}
[123] Fix | Delete
}
[124] Fix | Delete
// if integers are 64-bit - no other check required
[125] Fix | Delete
if ($hasINT64 || (($num <= PHP_INT_MAX) && ($num >= PHP_INT_MIN))) {
[126] Fix | Delete
return true;
[127] Fix | Delete
}
[128] Fix | Delete
return false;
[129] Fix | Delete
}
[130] Fix | Delete
[131] Fix | Delete
/**
[132] Fix | Delete
* Perform a division, guarding against division by zero
[133] Fix | Delete
*
[134] Fix | Delete
* @param float|int $numerator
[135] Fix | Delete
* @param float|int $denominator
[136] Fix | Delete
* @param float|int $fallback
[137] Fix | Delete
* @return float|int
[138] Fix | Delete
*/
[139] Fix | Delete
public static function SafeDiv($numerator, $denominator, $fallback = 0) {
[140] Fix | Delete
return $denominator ? $numerator / $denominator : $fallback;
[141] Fix | Delete
}
[142] Fix | Delete
[143] Fix | Delete
/**
[144] Fix | Delete
* @param string $fraction
[145] Fix | Delete
*
[146] Fix | Delete
* @return float
[147] Fix | Delete
*/
[148] Fix | Delete
public static function DecimalizeFraction($fraction) {
[149] Fix | Delete
list($numerator, $denominator) = explode('/', $fraction);
[150] Fix | Delete
return (int) $numerator / ($denominator ? $denominator : 1);
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
/**
[154] Fix | Delete
* @param string $binarynumerator
[155] Fix | Delete
*
[156] Fix | Delete
* @return float
[157] Fix | Delete
*/
[158] Fix | Delete
public static function DecimalBinary2Float($binarynumerator) {
[159] Fix | Delete
$numerator = self::Bin2Dec($binarynumerator);
[160] Fix | Delete
$denominator = self::Bin2Dec('1'.str_repeat('0', strlen($binarynumerator)));
[161] Fix | Delete
return ($numerator / $denominator);
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
/**
[165] Fix | Delete
* @link http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
[166] Fix | Delete
*
[167] Fix | Delete
* @param string $binarypointnumber
[168] Fix | Delete
* @param int $maxbits
[169] Fix | Delete
*
[170] Fix | Delete
* @return array
[171] Fix | Delete
*/
[172] Fix | Delete
public static function NormalizeBinaryPoint($binarypointnumber, $maxbits=52) {
[173] Fix | Delete
if (strpos($binarypointnumber, '.') === false) {
[174] Fix | Delete
$binarypointnumber = '0.'.$binarypointnumber;
[175] Fix | Delete
} elseif ($binarypointnumber[0] == '.') {
[176] Fix | Delete
$binarypointnumber = '0'.$binarypointnumber;
[177] Fix | Delete
}
[178] Fix | Delete
$exponent = 0;
[179] Fix | Delete
while (($binarypointnumber[0] != '1') || (substr($binarypointnumber, 1, 1) != '.')) {
[180] Fix | Delete
if (substr($binarypointnumber, 1, 1) == '.') {
[181] Fix | Delete
$exponent--;
[182] Fix | Delete
$binarypointnumber = substr($binarypointnumber, 2, 1).'.'.substr($binarypointnumber, 3);
[183] Fix | Delete
} else {
[184] Fix | Delete
$pointpos = strpos($binarypointnumber, '.');
[185] Fix | Delete
$exponent += ($pointpos - 1);
[186] Fix | Delete
$binarypointnumber = str_replace('.', '', $binarypointnumber);
[187] Fix | Delete
$binarypointnumber = $binarypointnumber[0].'.'.substr($binarypointnumber, 1);
[188] Fix | Delete
}
[189] Fix | Delete
}
[190] Fix | Delete
$binarypointnumber = str_pad(substr($binarypointnumber, 0, $maxbits + 2), $maxbits + 2, '0', STR_PAD_RIGHT);
[191] Fix | Delete
return array('normalized'=>$binarypointnumber, 'exponent'=>(int) $exponent);
[192] Fix | Delete
}
[193] Fix | Delete
[194] Fix | Delete
/**
[195] Fix | Delete
* @link http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/binary.html
[196] Fix | Delete
*
[197] Fix | Delete
* @param float $floatvalue
[198] Fix | Delete
*
[199] Fix | Delete
* @return string
[200] Fix | Delete
*/
[201] Fix | Delete
public static function Float2BinaryDecimal($floatvalue) {
[202] Fix | Delete
$maxbits = 128; // to how many bits of precision should the calculations be taken?
[203] Fix | Delete
$intpart = self::trunc($floatvalue);
[204] Fix | Delete
$floatpart = abs($floatvalue - $intpart);
[205] Fix | Delete
$pointbitstring = '';
[206] Fix | Delete
while (($floatpart != 0) && (strlen($pointbitstring) < $maxbits)) {
[207] Fix | Delete
$floatpart *= 2;
[208] Fix | Delete
$pointbitstring .= (string) self::trunc($floatpart);
[209] Fix | Delete
$floatpart -= self::trunc($floatpart);
[210] Fix | Delete
}
[211] Fix | Delete
$binarypointnumber = decbin($intpart).'.'.$pointbitstring;
[212] Fix | Delete
return $binarypointnumber;
[213] Fix | Delete
}
[214] Fix | Delete
[215] Fix | Delete
/**
[216] Fix | Delete
* @link http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee-expl.html
[217] Fix | Delete
*
[218] Fix | Delete
* @param float $floatvalue
[219] Fix | Delete
* @param int $bits
[220] Fix | Delete
*
[221] Fix | Delete
* @return string|false
[222] Fix | Delete
*/
[223] Fix | Delete
public static function Float2String($floatvalue, $bits) {
[224] Fix | Delete
$exponentbits = 0;
[225] Fix | Delete
$fractionbits = 0;
[226] Fix | Delete
switch ($bits) {
[227] Fix | Delete
case 32:
[228] Fix | Delete
$exponentbits = 8;
[229] Fix | Delete
$fractionbits = 23;
[230] Fix | Delete
break;
[231] Fix | Delete
[232] Fix | Delete
case 64:
[233] Fix | Delete
$exponentbits = 11;
[234] Fix | Delete
$fractionbits = 52;
[235] Fix | Delete
break;
[236] Fix | Delete
[237] Fix | Delete
default:
[238] Fix | Delete
return false;
[239] Fix | Delete
}
[240] Fix | Delete
if ($floatvalue >= 0) {
[241] Fix | Delete
$signbit = '0';
[242] Fix | Delete
} else {
[243] Fix | Delete
$signbit = '1';
[244] Fix | Delete
}
[245] Fix | Delete
$normalizedbinary = self::NormalizeBinaryPoint(self::Float2BinaryDecimal($floatvalue), $fractionbits);
[246] Fix | Delete
$biasedexponent = pow(2, $exponentbits - 1) - 1 + $normalizedbinary['exponent']; // (127 or 1023) +/- exponent
[247] Fix | Delete
$exponentbitstring = str_pad(decbin($biasedexponent), $exponentbits, '0', STR_PAD_LEFT);
[248] Fix | Delete
$fractionbitstring = str_pad(substr($normalizedbinary['normalized'], 2), $fractionbits, '0', STR_PAD_RIGHT);
[249] Fix | Delete
[250] Fix | Delete
return self::BigEndian2String(self::Bin2Dec($signbit.$exponentbitstring.$fractionbitstring), $bits % 8, false);
[251] Fix | Delete
}
[252] Fix | Delete
[253] Fix | Delete
/**
[254] Fix | Delete
* @param string $byteword
[255] Fix | Delete
*
[256] Fix | Delete
* @return float|false
[257] Fix | Delete
*/
[258] Fix | Delete
public static function LittleEndian2Float($byteword) {
[259] Fix | Delete
return self::BigEndian2Float(strrev($byteword));
[260] Fix | Delete
}
[261] Fix | Delete
[262] Fix | Delete
/**
[263] Fix | Delete
* ANSI/IEEE Standard 754-1985, Standard for Binary Floating Point Arithmetic
[264] Fix | Delete
*
[265] Fix | Delete
* @link https://web.archive.org/web/20120325162206/http://www.psc.edu/general/software/packages/ieee/ieee.php
[266] Fix | Delete
* @link http://www.scri.fsu.edu/~jac/MAD3401/Backgrnd/ieee.html
[267] Fix | Delete
*
[268] Fix | Delete
* @param string $byteword
[269] Fix | Delete
*
[270] Fix | Delete
* @return float|false
[271] Fix | Delete
*/
[272] Fix | Delete
public static function BigEndian2Float($byteword) {
[273] Fix | Delete
$bitword = self::BigEndian2Bin($byteword);
[274] Fix | Delete
if (!$bitword) {
[275] Fix | Delete
return 0;
[276] Fix | Delete
}
[277] Fix | Delete
$signbit = $bitword[0];
[278] Fix | Delete
$floatvalue = 0;
[279] Fix | Delete
$exponentbits = 0;
[280] Fix | Delete
$fractionbits = 0;
[281] Fix | Delete
[282] Fix | Delete
switch (strlen($byteword) * 8) {
[283] Fix | Delete
case 32:
[284] Fix | Delete
$exponentbits = 8;
[285] Fix | Delete
$fractionbits = 23;
[286] Fix | Delete
break;
[287] Fix | Delete
[288] Fix | Delete
case 64:
[289] Fix | Delete
$exponentbits = 11;
[290] Fix | Delete
$fractionbits = 52;
[291] Fix | Delete
break;
[292] Fix | Delete
[293] Fix | Delete
case 80:
[294] Fix | Delete
// 80-bit Apple SANE format
[295] Fix | Delete
// http://www.mactech.com/articles/mactech/Vol.06/06.01/SANENormalized/
[296] Fix | Delete
$exponentstring = substr($bitword, 1, 15);
[297] Fix | Delete
$isnormalized = intval($bitword[16]);
[298] Fix | Delete
$fractionstring = substr($bitword, 17, 63);
[299] Fix | Delete
$exponent = pow(2, self::Bin2Dec($exponentstring) - 16383);
[300] Fix | Delete
$fraction = $isnormalized + self::DecimalBinary2Float($fractionstring);
[301] Fix | Delete
$floatvalue = $exponent * $fraction;
[302] Fix | Delete
if ($signbit == '1') {
[303] Fix | Delete
$floatvalue *= -1;
[304] Fix | Delete
}
[305] Fix | Delete
return $floatvalue;
[306] Fix | Delete
[307] Fix | Delete
default:
[308] Fix | Delete
return false;
[309] Fix | Delete
}
[310] Fix | Delete
$exponentstring = substr($bitword, 1, $exponentbits);
[311] Fix | Delete
$fractionstring = substr($bitword, $exponentbits + 1, $fractionbits);
[312] Fix | Delete
$exponent = self::Bin2Dec($exponentstring);
[313] Fix | Delete
$fraction = self::Bin2Dec($fractionstring);
[314] Fix | Delete
[315] Fix | Delete
if (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction != 0)) {
[316] Fix | Delete
// Not a Number
[317] Fix | Delete
$floatvalue = NAN;
[318] Fix | Delete
} elseif (($exponent == (pow(2, $exponentbits) - 1)) && ($fraction == 0)) {
[319] Fix | Delete
if ($signbit == '1') {
[320] Fix | Delete
$floatvalue = -INF;
[321] Fix | Delete
} else {
[322] Fix | Delete
$floatvalue = INF;
[323] Fix | Delete
}
[324] Fix | Delete
} elseif (($exponent == 0) && ($fraction == 0)) {
[325] Fix | Delete
if ($signbit == '1') {
[326] Fix | Delete
$floatvalue = -0.0;
[327] Fix | Delete
} else {
[328] Fix | Delete
$floatvalue = 0.0;
[329] Fix | Delete
}
[330] Fix | Delete
} elseif (($exponent == 0) && ($fraction != 0)) {
[331] Fix | Delete
// These are 'unnormalized' values
[332] Fix | Delete
$floatvalue = pow(2, (-1 * (pow(2, $exponentbits - 1) - 2))) * self::DecimalBinary2Float($fractionstring);
[333] Fix | Delete
if ($signbit == '1') {
[334] Fix | Delete
$floatvalue *= -1;
[335] Fix | Delete
}
[336] Fix | Delete
} elseif ($exponent != 0) {
[337] Fix | Delete
$floatvalue = pow(2, ($exponent - (pow(2, $exponentbits - 1) - 1))) * (1 + self::DecimalBinary2Float($fractionstring));
[338] Fix | Delete
if ($signbit == '1') {
[339] Fix | Delete
$floatvalue *= -1;
[340] Fix | Delete
}
[341] Fix | Delete
}
[342] Fix | Delete
return (float) $floatvalue;
[343] Fix | Delete
}
[344] Fix | Delete
[345] Fix | Delete
/**
[346] Fix | Delete
* @param string $byteword
[347] Fix | Delete
* @param bool $synchsafe
[348] Fix | Delete
* @param bool $signed
[349] Fix | Delete
*
[350] Fix | Delete
* @return int|float|false
[351] Fix | Delete
* @throws Exception
[352] Fix | Delete
*/
[353] Fix | Delete
public static function BigEndian2Int($byteword, $synchsafe=false, $signed=false) {
[354] Fix | Delete
$intvalue = 0;
[355] Fix | Delete
$bytewordlen = strlen($byteword);
[356] Fix | Delete
if ($bytewordlen == 0) {
[357] Fix | Delete
return false;
[358] Fix | Delete
}
[359] Fix | Delete
for ($i = 0; $i < $bytewordlen; $i++) {
[360] Fix | Delete
if ($synchsafe) { // disregard MSB, effectively 7-bit bytes
[361] Fix | Delete
//$intvalue = $intvalue | (ord($byteword{$i}) & 0x7F) << (($bytewordlen - 1 - $i) * 7); // faster, but runs into problems past 2^31 on 32-bit systems
[362] Fix | Delete
$intvalue += (ord($byteword[$i]) & 0x7F) * pow(2, ($bytewordlen - 1 - $i) * 7);
[363] Fix | Delete
} else {
[364] Fix | Delete
$intvalue += ord($byteword[$i]) * pow(256, ($bytewordlen - 1 - $i));
[365] Fix | Delete
}
[366] Fix | Delete
}
[367] Fix | Delete
if ($signed && !$synchsafe) {
[368] Fix | Delete
// synchsafe ints are not allowed to be signed
[369] Fix | Delete
if ($bytewordlen <= PHP_INT_SIZE) {
[370] Fix | Delete
$signMaskBit = 0x80 << (8 * ($bytewordlen - 1));
[371] Fix | Delete
if ($intvalue & $signMaskBit) {
[372] Fix | Delete
$intvalue = 0 - ($intvalue & ($signMaskBit - 1));
[373] Fix | Delete
}
[374] Fix | Delete
} else {
[375] Fix | Delete
throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits ('.strlen($byteword).') in self::BigEndian2Int()');
[376] Fix | Delete
}
[377] Fix | Delete
}
[378] Fix | Delete
return self::CastAsInt($intvalue);
[379] Fix | Delete
}
[380] Fix | Delete
[381] Fix | Delete
/**
[382] Fix | Delete
* @param string $byteword
[383] Fix | Delete
* @param bool $signed
[384] Fix | Delete
*
[385] Fix | Delete
* @return int|float|false
[386] Fix | Delete
*/
[387] Fix | Delete
public static function LittleEndian2Int($byteword, $signed=false) {
[388] Fix | Delete
return self::BigEndian2Int(strrev($byteword), false, $signed);
[389] Fix | Delete
}
[390] Fix | Delete
[391] Fix | Delete
/**
[392] Fix | Delete
* @param string $byteword
[393] Fix | Delete
*
[394] Fix | Delete
* @return string
[395] Fix | Delete
*/
[396] Fix | Delete
public static function LittleEndian2Bin($byteword) {
[397] Fix | Delete
return self::BigEndian2Bin(strrev($byteword));
[398] Fix | Delete
}
[399] Fix | Delete
[400] Fix | Delete
/**
[401] Fix | Delete
* @param string $byteword
[402] Fix | Delete
*
[403] Fix | Delete
* @return string
[404] Fix | Delete
*/
[405] Fix | Delete
public static function BigEndian2Bin($byteword) {
[406] Fix | Delete
$binvalue = '';
[407] Fix | Delete
$bytewordlen = strlen($byteword);
[408] Fix | Delete
for ($i = 0; $i < $bytewordlen; $i++) {
[409] Fix | Delete
$binvalue .= str_pad(decbin(ord($byteword[$i])), 8, '0', STR_PAD_LEFT);
[410] Fix | Delete
}
[411] Fix | Delete
return $binvalue;
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
/**
[415] Fix | Delete
* @param int $number
[416] Fix | Delete
* @param int $minbytes
[417] Fix | Delete
* @param bool $synchsafe
[418] Fix | Delete
* @param bool $signed
[419] Fix | Delete
*
[420] Fix | Delete
* @return string
[421] Fix | Delete
* @throws Exception
[422] Fix | Delete
*/
[423] Fix | Delete
public static function BigEndian2String($number, $minbytes=1, $synchsafe=false, $signed=false) {
[424] Fix | Delete
if ($number < 0) {
[425] Fix | Delete
throw new Exception('ERROR: self::BigEndian2String() does not support negative numbers');
[426] Fix | Delete
}
[427] Fix | Delete
$maskbyte = (($synchsafe || $signed) ? 0x7F : 0xFF);
[428] Fix | Delete
$intstring = '';
[429] Fix | Delete
if ($signed) {
[430] Fix | Delete
if ($minbytes > PHP_INT_SIZE) {
[431] Fix | Delete
throw new Exception('ERROR: Cannot have signed integers larger than '.(8 * PHP_INT_SIZE).'-bits in self::BigEndian2String()');
[432] Fix | Delete
}
[433] Fix | Delete
$number = $number & (0x80 << (8 * ($minbytes - 1)));
[434] Fix | Delete
}
[435] Fix | Delete
while ($number != 0) {
[436] Fix | Delete
$quotient = ($number / ($maskbyte + 1));
[437] Fix | Delete
$intstring = chr(ceil(($quotient - floor($quotient)) * $maskbyte)).$intstring;
[438] Fix | Delete
$number = floor($quotient);
[439] Fix | Delete
}
[440] Fix | Delete
return str_pad($intstring, $minbytes, "\x00", STR_PAD_LEFT);
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
/**
[444] Fix | Delete
* @param int|string $number
[445] Fix | Delete
*
[446] Fix | Delete
* @return string
[447] Fix | Delete
*/
[448] Fix | Delete
public static function Dec2Bin($number) {
[449] Fix | Delete
if (!is_numeric($number)) {
[450] Fix | Delete
// https://github.com/JamesHeinrich/getID3/issues/299
[451] Fix | Delete
trigger_error('TypeError: Dec2Bin(): Argument #1 ($number) must be numeric, '.gettype($number).' given', E_USER_WARNING);
[452] Fix | Delete
return '';
[453] Fix | Delete
}
[454] Fix | Delete
$bytes = array();
[455] Fix | Delete
while ($number >= 256) {
[456] Fix | Delete
$bytes[] = (int) (($number / 256) - (floor($number / 256))) * 256;
[457] Fix | Delete
$number = floor($number / 256);
[458] Fix | Delete
}
[459] Fix | Delete
$bytes[] = (int) $number;
[460] Fix | Delete
$binstring = '';
[461] Fix | Delete
foreach ($bytes as $i => $byte) {
[462] Fix | Delete
$binstring = (($i == count($bytes) - 1) ? decbin($byte) : str_pad(decbin($byte), 8, '0', STR_PAD_LEFT)).$binstring;
[463] Fix | Delete
}
[464] Fix | Delete
return $binstring;
[465] Fix | Delete
}
[466] Fix | Delete
[467] Fix | Delete
/**
[468] Fix | Delete
* @param string $binstring
[469] Fix | Delete
* @param bool $signed
[470] Fix | Delete
*
[471] Fix | Delete
* @return int|float
[472] Fix | Delete
*/
[473] Fix | Delete
public static function Bin2Dec($binstring, $signed=false) {
[474] Fix | Delete
$signmult = 1;
[475] Fix | Delete
if ($signed) {
[476] Fix | Delete
if ($binstring[0] == '1') {
[477] Fix | Delete
$signmult = -1;
[478] Fix | Delete
}
[479] Fix | Delete
$binstring = substr($binstring, 1);
[480] Fix | Delete
}
[481] Fix | Delete
$decvalue = 0;
[482] Fix | Delete
for ($i = 0; $i < strlen($binstring); $i++) {
[483] Fix | Delete
$decvalue += ((int) substr($binstring, strlen($binstring) - $i - 1, 1)) * pow(2, $i);
[484] Fix | Delete
}
[485] Fix | Delete
return self::CastAsInt($decvalue * $signmult);
[486] Fix | Delete
}
[487] Fix | Delete
[488] Fix | Delete
/**
[489] Fix | Delete
* @param string $binstring
[490] Fix | Delete
*
[491] Fix | Delete
* @return string
[492] Fix | Delete
*/
[493] Fix | Delete
public static function Bin2String($binstring) {
[494] Fix | Delete
// return 'hi' for input of '0110100001101001'
[495] Fix | Delete
$string = '';
[496] Fix | Delete
$binstringreversed = strrev($binstring);
[497] Fix | Delete
for ($i = 0; $i < strlen($binstringreversed); $i += 8) {
[498] Fix | Delete
$string = chr(self::Bin2Dec(strrev(substr($binstringreversed, $i, 8)))).$string;
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function