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

在我的特殊情况下,发生了两件事。

  1. 腻子不知何故无视我明确的“使用utf-8”设置
  2. 我使用的类没有将 id3 标签复制到“comments_html”错误。当我打印结果时,我发现通过访问实际标签,我能够访问未损坏的 utf-8
于 2010-06-30T15:31:53.830 回答