获取带日语字符的ID3标签 - PHP

时间:2017-11-16 03:27:00

标签: php id3 cjk

所以我提出了一个问题,每次我上传一个mp3文件并获得它的id3标签,例如标题,艺术家等等,并且它是日文字符格式,它将被存储到数据库中或由php处理作为一组字母和特殊字符。数据库已设置为接收日语字符。但我不知道为什么每次处理id3标签时编码都会是这样的。这是我的代码。

 public function getTagsInfo($sFilepath) {
    $aTV23 = array( // array of possible sys tags (for last version of ID3)
        'TIT2',
        'TALB',
        'TPE1',
        'TPE2',
        'TRCK',
        'TYER',
        'TLEN',
        'USLT',
        'TPOS',
        'TCON',
        'TENC',
        'TCOP',
        'TPUB',
        'TOPE',
        'WXXX',
        'COMM',
        'TCOM'
    );
    $aTV23t = array( // array of titles for sys tags
        'Title',
        'Album',
        'Author',
        'AlbumAuthor',
        'Track',
        'Year',
        'Lenght',
        'Lyric',
        'Desc',
        'Genre',
        'Encoded',
        'Copyright',
        'Publisher',
        'OriginalArtist',
        'URL',
        'Comments',
        'Composer'
    );
    $aTV22 = array( // array of possible sys tags (for old version of ID3)
        'TT2',
        'TAL',
        'TP1',
        'TRK',
        'TYE',
        'TLE',
        'ULT'
    );
    $aTV22t = array( // array of titles for sys tags
        'Title',
        'Album',
        'Author',
        'Track',
        'Year',
        'Lenght',
        'Lyric'
    );

   $aTV23 = mb_convert_encoding($aTV23, "UTF-8");
   $aTV23t = mb_convert_encoding($aTV23t, "UTF-8");
   $aTV22 = mb_convert_encoding($aTV22, "UTF-8");
   $aTV22t = mb_convert_encoding($aTV22t, "UTF-8");
    // read source file
    $iFSize = filesize($sFilepath);
    $vFD = fopen($sFilepath,'r');
    $sSrc = fread($vFD,$iFSize);
    fclose($vFD);
    // obtain base info
    if (substr($sSrc,0,3) == 'ID3') {
        $aInfo['FileName'] = $sFilepath;
        $aInfo['Version'] = hexdec(bin2hex(substr($sSrc,3,1))).'.'.hexdec(bin2hex(substr($sSrc,4,1)));
    }
    // passing through possible tags of idv2 (v3 and v4)
    if ($aInfo['Version'] == '4.0' || $aInfo['Version'] == '3.0') {
        for ($i = 0; $i < count($aTV23); $i++) {
            if (strpos($sSrc, $aTV23[$i].chr(0)) != FALSE) {
                $s = '';
                $iPos = strpos($sSrc, $aTV23[$i].chr(0));
                $iLen = hexdec(bin2hex(substr($sSrc,($iPos + 5),3)));
                $data = substr($sSrc, $iPos, 10 + $iLen);
                for ($a = 0; $a < strlen($data); $a++) {
                    $char = substr($data, $a, 1);
                    if ($char >= ' ' && $char <= '~')
                        $s .= $char;
                }
                if (substr($s, 0, 4) == $aTV23[$i]) {
                    $iSL = 4;
                    if ($aTV23[$i] == 'USLT') {
                        $iSL = 7;
                    } elseif ($aTV23[$i] == 'TALB') {
                        $iSL = 5;
                    } elseif ($aTV23[$i] == 'TENC') {
                        $iSL = 6;
                    }
                    $aInfo[$aTV23t[$i]] = substr($s, $iSL);
                }
            }
        }
    }
    // passing through possible tags of idv2 (v2)
    if($aInfo['Version'] == '2.0') {
        for ($i = 0; $i < count($aTV22); $i++) {
            if (strpos($sSrc, $aTV22[$i].chr(0)) != FALSE) {
                $s = '';
                $iPos = strpos($sSrc, $aTV22[$i].chr(0));
                $iLen = hexdec(bin2hex(substr($sSrc,($iPos + 3),3)));
                $data = substr($sSrc, $iPos, 6 + $iLen);
                for ($a = 0; $a < strlen($data); $a++) {
                    $char = substr($data, $a, 1);
                    if ($char >= ' ' && $char <= '~')
                        $s .= $char;
                }
                if (substr($s, 0, 3) == $aTV22[$i]) {
                    $iSL = 3;
                    if ($aTV22[$i] == 'ULT') {
                        $iSL = 6;
                    }
                    $aInfo[$aTV22t[$i]] = substr($s, $iSL);
                }
            }
        }
    }
    return $aInfo;
}

结果:

あなたを武装解除する converted automatically to B0j0_00fkdY00

0 个答案:

没有答案