0

私はphp cliスクリプトを取得してフォルダーを通過させ、id3タグを取得しようとしています。これはキリル文字ではutf8ですが、データベースにはあります。スクリプトを実行すると、次のようなDBフィールドで生のutfを取得します"Àëáåíà"

ここにスクリプトがあります

<?
set_time_limit(0);

include('classes/adodb5/adodb.inc.php');
include ('classes/id3/getid3.php');

$ftpdir = "/radio/unprocessed/";
$processeddir = "/radio/music";

//set up the database

$conn = &ADONewConnection('mysql');
$conn->PConnect('localhost','root', '**********','radio');

$utf = $conn->Execute("SET NAMES 'UTF8';");
$charset = $conn->Execute("CHARSET UTF8;");

//function for processing the actual file
function processmp3($fn, $folder, $conn){
                        $getID3 = new getID3;
                        $ThisFileInfo = $getID3->analyze($folder.$fn);
                        //this is needed to consolidate all tag formats
                        getid3_lib::CopyTagsToComments($ThisFileInfo);
                        if (array_key_exists('artist', $ThisFileInfo['comments_html'])&& array_key_exists('artist', $ThisFileInfo['comments_html'])){
                                $artist=($ThisFileInfo['comments_html']['artist'][0]);
                                $title=($ThisFileInfo['comments_html']['title'][0]);
                        }else{$artist ='not defined'; $title="not defined";}
                        //random name
 //random name
                        $rand_name = md5(time()).rand(1,1000).".mp3";
                        //movefile
                        //rename($folder.$fn,'/radio/music/'.$rand_name);
                        //put in DB
                        $insert = $conn->Execute('INSERT INTO unprocesseds VALUES("","'.$artist.'","'.$title.'","'.$rand_name.'","'.$fn.'");');
                        }


//cyccle through contents
if($handle = opendir($ftpdir)){
        while(false !== ($file = readdir($handle))){
                $type = mime_content_type($ftpdir.$file);
                if ($type=='audio/mpeg'){processmp3($file, $ftpdir, $conn);}
                else {
                        if(is_file($ftpdir.$file)){unlink($ftpdir.$file);}
                        }
                }


        }

closedir($handle);
4

1 に答える 1

0

私の特定のケースでは、2つのことが起こっていました。

  1. パテはどういうわけか私の明示的な「use utf-8」設定を無視していました
  2. 私が使用していたクラスは、id3 タグを「comments_html」に間違ってコピーしていませんでした。結果をprint_rしたところ、実際のタグにアクセスすることで、破損していないutf-8に到達できることがわかりました
于 2010-06-30T15:31:53.830 に答える