php id3 dll,PHP - Manual: ID3 函数 (官方文档)

Windows XP users may be having trouble with routines provided here and may (as above) only have access to "read" classes. The following very simplified "write" can be used for replacing Windows Media Player file tags, and with care and adjustments, can be used more generally.

define(_Title,"TIT2");define(_Artist,"TPE1");define(_Group,"TPE2");define(_Album,"TALB");define(_Genre,"TCON");define(_TrackNo,"TRCK");define(_Year,"TYER");$frames= array(_Album=>"The Ultimate Experience",_TrackNo=>"1",_Title=>"All along the watchtower",_Artist=>"Jimi Hendrix",_Group=>"",_Year=>"19xx",_Genre=>"Rock");#..........................................

#       WRITE ID3 TAGS (Write MP3 [v1, v2]

#..........................................functionwriteTags($mp3) {$fl=file_get_contents($mp3);$Header=substr($fl,0,10);$tagLen=calcDecTagLen(substr($Header,6,4),$tagLen);$music=substr($fl,$tagLen+10,-128);# Can use input Header for output but you may

# wish to change the output filename for testing$tagLen=1024;# or whatever you like >your actual$Header=substr($Header,0,6).setHexTagLen($tagLen);file_put_contents($mp3,mkV2Tag($Header,$tagLen).$music.mkV1Tag());

}#   Create the V2 tagfunctionmkV2Tag($Hdr,$tagLen) {

Global$frames;$null=chr(0);$nl3=$null.$null.$null;# 0 bytes for flags and encoding$out="";

foreach($framesas$ky=>$val) {$n=strlen($val)+1;$out.=$ky.mkFrmLen($n).$nl3.$val;

}

return$Hdr.str_pad($out,$tagLen,$null);

}#    Calculate Tag Length from bytes 6-10 of existing headerfunctioncalcDecTagLen($word) {$m=1;$int=0;

for ($i=strlen($word)-1;$i>-1;$i--) {$int+=$m*ord($word[$i]);$m=$m*128;

}

return$int;

}#    Make the 4 byte frame length value for the V2tagfunctionmkFrmLen($int) {$hx="";

while ($int>0) {$n=$int%256;$hx=chr($n).$hx;$int=floor($int/256);

}

returnstr_pad($hx,4,chr(0),STR_PAD_LEFT);

}#    Create the 128 byte V1 tagfunctionmkV1Tag() {

Global$frames;$tagOut="TAG".adj($frames[_Title]).adj($frames[_Artist]).adj($frames[_Album]).str_pad($frames[_Year],4).str_pad(" ",29," ").chr($frames[_TrackNo]).chr($n);

return$tagOut;

}#    Pad the header to 30 charactersfunctionadj($str) {

returnsubstr(str_pad($str,30,chr(0)),0,30);

}#     This is a simple example for an mp3 in current folderwriteTags("01-Cognac Blues.mp3");?>

The setHexTagLen can be figured out from the calcDecTagLen but here's some sample code.

for ($i=0;$i<4;$i++) {$m.=chr(floor($intVar/$n));$intVar=$intVar%$n;$n=$n/128;

}

return$m;

}?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值