简体   繁体   English

PHP的问题,在cli脚本中读取id3标签进行编码

[英]php problem with encoding in a cli script reading id3 tags

i am trying to get a php cli script to go through a folder, get the id3 tags, which are in utf8 in cyrillic and but it in the database. 我正在尝试获取一个php cli脚本来通过一个文件夹,获取id3标记,这些标记在西里尔文的utf8中,但是在数据库中。 when i execute the script i get the raw utf in the DB fields like "Àëáåíà" 当我执行脚本时,我在诸如"Àëáåíà"类的DB字段中得到原始的utf "Àëáåíà"

here is the script 这是脚本

<?
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);

In my particular case 2 things were happening. 在我的特定情况下,发生了2件事。

  1. Putty was somehow disregarding my explicit "use utf-8" settings 腻子以某种方式无视我的显式“使用utf-8”设置
  2. The class i was using was not copying id3 tags to "comments_html" wrong. 我正在使用的类没有将id3标记复制到“ comments_html”错误。 When i print_r-ed the result, i found that by accessing the actual tag i was able to get to the uncorrupted utf-8 当我print_r-ed结果时,我发现通过访问实际标签我能够进入未损坏的utf-8

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM