【问题标题】:php problem with encoding in a cli script reading id3 tags在读取 id3 标签的 cli 脚本中编码的 php 问题
【发布时间】:2010-06-29 15:24:46
【问题描述】:

我试图让一个 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);

【问题讨论】:

    标签: php mysql encoding utf-8 id3


    【解决方案1】:

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

    1. Putty 不知何故无视我明确的“使用 utf-8”设置
    2. 我使用的类没有将 id3 标签复制到“cmets_html”错误。当我打印结果时,我发现通过访问实际标签,我能够访问未损坏的 utf-8

    【讨论】:

      猜你喜欢
      • 2011-08-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2015-07-21
      相关资源
      最近更新 更多