在 XAMPP (Windows) 上安装 PECL 扩展
Posted
技术标签:
【中文标题】在 XAMPP (Windows) 上安装 PECL 扩展【英文标题】:PECL extension installation on XAMPP (Windows) 【发布时间】:2020-09-21 20:56:34 【问题描述】:我需要一些帮助,我已经尝试过,但还没有接近获胜的想法。
我需要在 Windows 的 XAMPP(v7.4.5) 上运行 ID3 PECL。
昨天我花了一天时间尝试通过 php.net 网站上的PECL articles 工作,不幸的是,这对我来说没有多大意义,因为我的知识还没有达到那个水平。我也尝试过寻找 ID3 扩展名的 dll 文件,但找不到任何文件。 ID3 PECL 页面只有源文件可供下载。
也许有人有足够的耐心,可以用更通俗的语言来解释这个过程……对我来说是愚蠢的吗?
我们将不胜感激。
编辑
有人可以帮忙吗?
在 Lelio 的帮助下,我现在有了一种从 MP3 中提取信息的方法,我添加了两行来访问 Genre 以及 Attached Picture 块。 Genre 块有效。但是,附加图片块没有。
这是更新后的代码,它保存为一个单独的名为 script-mp3-tag-reader.php 的 php 文件:
<?php
function tagReader($file)
$id3v23 = array("TIT2","TALB","TPE1","TRCK","TDRC","TLEN","USLT","TCON","APIC");
$id3v22 = array("TT2","TAL","TP1","TRK","TYE","TLE","ULT","TCO");
$fsize = filesize($file);
$fd = fopen($file,"r");
$tag = fread($fd,$fsize);
$tmp = "";
fclose($fd);
if (substr($tag,0,3) == "ID3")
$result['FileName'] = $file;
$result['TAG'] = substr($tag,0,3);
$result['Version'] = hexdec(bin2hex(substr($tag,3,1))).".".hexdec(bin2hex(substr($tag,4,1)));
if($result['Version'] == "4.0" || $result['Version'] == "3.0")
for ($i=0;$i<count($id3v23);$i++)
if (strpos($tag,$id3v23[$i].chr(0))!= FALSE)
$pos = strpos($tag, $id3v23[$i].chr(0));
$len = hexdec(bin2hex(substr($tag,($pos+5),3)));
$data = substr($tag, $pos, 9+$len);
for ($a=0;$a<strlen($data);$a++)
$char = substr($data,$a,1);
if($char >= " " && $char <= "~")
$tmp.=$char;
if(substr($tmp,0,4) == "TIT2") $result['Title'] = substr($tmp,4);
if(substr($tmp,0,4) == "TALB") $result['Album'] = substr($tmp,4);
if(substr($tmp,0,4) == "TPE1") $result['Artist'] = substr($tmp,4);
if(substr($tmp,0,4) == "TRCK") $result['TrackNo'] = substr($tmp,4);
if(substr($tmp,0,4) == "TDRC") $result['Year'] = substr($tmp,4);
if(substr($tmp,0,4) == "TLEN") $result['Lenght'] = substr($tmp,4);
if(substr($tmp,0,4) == "USLT") $result['Lyric'] = substr($tmp,7);
if(substr($tmp,0,4) == "TCON") $result['Genre'] = substr($tmp,4);
if(substr($tmp,0,4) == "APIC") $result['AttachedPicture'] = substr($tmp,4);
$tmp = "";
if($result['Version'] == "2.0")
for ($i=0;$i<count($id3v22);$i++)
if (strpos($tag,$id3v22[$i].chr(0))!= FALSE)
$pos = strpos($tag, $id3v22[$i].chr(0));
$len = hexdec(bin2hex(substr($tag,($pos+3),3)));
$data = substr($tag, $pos, 6+$len);
for ($a=0;$a<strlen($data);$a++)
$char = substr($data,$a,1);
if($char >= " " && $char <= "~")
$tmp.=$char;
if(substr($tmp,0,3) == "TT2") $result['Title'] = substr($tmp,3);
if(substr($tmp,0,3) == "TAL") $result['Album'] = substr($tmp,3);
if(substr($tmp,0,3) == "TP1") $result['Artist'] = substr($tmp,3);
if(substr($tmp,0,3) == "TRK") $result['TrackNo'] = substr($tmp,3);
if(substr($tmp,0,3) == "TYE") $result['Year'] = substr($tmp,3);
if(substr($tmp,0,3) == "TLE") $result['Lenght'] = substr($tmp,3);
if(substr($tmp,0,3) == "ULT") $result['Lyric'] = substr($tmp,6);
if(substr($tmp,0,3) == "TCO") $result['Genre'] = substr($tmp,3);
if(substr($tmp,0,3) == "PIC") $result['AttachedPicture'] = base64_encode(substr($tmp,3));
$tmp = "";
return $result;
?>
在我的 index.php 文件中,我然后加载并使用上述 PHP 脚本,如下所示:
<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/script/php/script-mp3-tag-reader.php');
$mp3 = $_SERVER['DOCUMENT_ROOT'].'/media/audio/mp3/test_audio.mp3';
$myResult = tagReader($mp3);
print_r($myResult);
?>
当查看print_r($myresult);
时,可以看到信息确实存在并且正确......只是不是附加图像部分。我似乎提取的东西远远超出了需要,而且不知道如何只访问我需要的东西。
【问题讨论】:
@LelioFaieta,正如我上面问题的一部分所述,是的,我有并且无法理解它。 这是一个非常清晰的指南,有什么问题? 顺便说一句,ID3,如您的链接中所述,未维护。您确定要安装 16 年前最后一次更新的东西吗?它可能与 php 5 或 7 不兼容 @LelioFaieta Clear,也许对你来说是的。 @LelioFaieta 您对可能有用的替代方案有什么建议吗? 【参考方案1】:这样的事情应该可以解决问题。它最近没有经过测试,但应该可以从 mp3 文件中读取您要查找的数据。
function tagReader($file)
$id3v23 = array("TIT2","TALB","TPE1","TRCK","TDRC","TLEN","USLT");
$id3v22 = array("TT2","TAL","TP1","TRK","TYE","TLE","ULT");
$fsize = filesize($file);
$fd = fopen($file,"r");
$tag = fread($fd,$fsize);
$tmp = "";
fclose($fd);
if (substr($tag,0,3) == "ID3")
$result['FileName'] = $file;
$result['TAG'] = substr($tag,0,3);
$result['Version'] = hexdec(bin2hex(substr($tag,3,1))).".".hexdec(bin2hex(substr($tag,4,1)));
if($result['Version'] == "4.0" || $result['Version'] == "3.0")
for ($i=0;$i<count($id3v23);$i++)
if (strpos($tag,$id3v23[$i].chr(0))!= FALSE)
$pos = strpos($tag, $id3v23[$i].chr(0));
$len = hexdec(bin2hex(substr($tag,($pos+5),3)));
$data = substr($tag, $pos, 9+$len);
for ($a=0;$a<strlen($data);$a++)
$char = substr($data,$a,1);
if($char >= " " && $char <= "~") $tmp.=$char;
if(substr($tmp,0,4) == "TIT2") $result['Title'] = substr($tmp,4);
if(substr($tmp,0,4) == "TALB") $result['Album'] = substr($tmp,4);
if(substr($tmp,0,4) == "TPE1") $result['Author'] = substr($tmp,4);
if(substr($tmp,0,4) == "TRCK") $result['Track'] = substr($tmp,4);
if(substr($tmp,0,4) == "TDRC") $result['Year'] = substr($tmp,4);
if(substr($tmp,0,4) == "TLEN") $result['Lenght'] = substr($tmp,4);
if(substr($tmp,0,4) == "USLT") $result['Lyric'] = substr($tmp,7);
$tmp = "";
if($result['Version'] == "2.0")
for ($i=0;$i<count($id3v22);$i++)
if (strpos($tag,$id3v22[$i].chr(0))!= FALSE)
$pos = strpos($tag, $id3v22[$i].chr(0));
$len = hexdec(bin2hex(substr($tag,($pos+3),3)));
$data = substr($tag, $pos, 6+$len);
for ($a=0;$a<strlen($data);$a++)
$char = substr($data,$a,1);
if($char >= " " && $char <= "~") $tmp.=$char;
if(substr($tmp,0,3) == "TT2") $result['Title'] = substr($tmp,3);
if(substr($tmp,0,3) == "TAL") $result['Album'] = substr($tmp,3);
if(substr($tmp,0,3) == "TP1") $result['Author'] = substr($tmp,3);
if(substr($tmp,0,3) == "TRK") $result['Track'] = substr($tmp,3);
if(substr($tmp,0,3) == "TYE") $result['Year'] = substr($tmp,3);
if(substr($tmp,0,3) == "TLE") $result['Lenght'] = substr($tmp,3);
if(substr($tmp,0,3) == "ULT") $result['Lyric'] = substr($tmp,6);
$tmp = "";
return $result;
【讨论】:
非常感谢您,您是救生员!这似乎有效。你介意麻烦把它分解一下,这样我就可以学到一些东西吗? 有没有办法从 MP3 中提取附件图片? 这段代码忽略了ID3v2版本的各种细节,比如不同的文本编码、去同步和压缩。这也不是OP问题的解决方案,只是一种替代方案。大文件会失败。 @AmigoJack 您是否阅读了我回答开头的免责声明?另外,如果您对 OP 的问题有更好的解决方案,请随时添加! 是的:它遗漏了所有细节,就像代码遗漏了很多 cmets。免责声明既不是治疗者也不是借口。以上是关于在 XAMPP (Windows) 上安装 PECL 扩展的主要内容,如果未能解决你的问题,请参考以下文章
如何在 Windows 8 上使用 wamp 或 xampp 安装 pimcore?
使用 XAMPP 在 Windows 8 上安装 Wordpress 但 PHP 未运行