php 创建临时id

ID3 Tags Reader with PHP Today we will work with PHP again. Today’s tutorial will tell you about how you can use PHP to obtain ID3 meta info from music files (mp3). The easiest way to save id3 info – winamp software (try to find it in old archives). So you will able to test our result script with your music files. We will extract next fields: Title, Album, Author, Discription, Genre, Publisher, OriginalArtist, URL etc.

使用PHP的ID3标签阅读器今天,我们将再次使用PHP。 今天的教程将告诉您如何使用PHP从音乐文件(mp3)中获取ID3元信息。 保存id3信息的最简单方法-winamp软件(尝试在旧的归档文件中找到它)。 因此,您将能够使用您的音乐文件测试我们的结果脚本。 我们将提取下一个字段:标题,专辑,作者,标题,类型,出版商,原始艺术家,URL等。

现场演示

[sociallocker]

[社交储物柜]

打包下载

[/sociallocker]

[/ sociallocker]

Now – download the example files and lets start coding !

现在,下载示例文件并开始编码!

步骤1. HTML (Step 1. HTML)

As usual, we start with the HTML. This is source of demo page layout:

和往常一样,我们从HTML开始。 这是演示页面布局的来源:

main_page.html (main_page.html)


<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>ID3 Tags Reader with PHP | Script-tutorials</title><link rel="stylesheet" href="css/main.css" type="text/css" media="all" />
</head>
<body><div class="example" id="main"><table style="width:100%"><thead><td><b>Title</b></td><td><b>Album</b></td><td><b>Author</b></td><td><b>AlbumAuthor</b></td><td><b>Track</b></td><td><b>Year</b></td><td><b>Lenght</b></td><td><b>Lyric</b></td><td><b>Desc</b></td><td><b>Genre</b></td></thead>__list__</table><hr /><h3>Extra info</h3><table style="width:100%"><thead><td><b>Title</b></td><td><b>Encoded</b></td><td><b>Copyright</b></td><td><b>Publisher</b></td><td><b>OriginalArtist</b></td><td><b>URL</b></td><td><b>Comments</b></td><td><b>Composer</b></td></thead>__list2__</table></div>
</body>
</html>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head><title>ID3 Tags Reader with PHP | Script-tutorials</title><link rel="stylesheet" href="css/main.css" type="text/css" media="all" />
</head>
<body><div class="example" id="main"><table style="width:100%"><thead><td><b>Title</b></td><td><b>Album</b></td><td><b>Author</b></td><td><b>AlbumAuthor</b></td><td><b>Track</b></td><td><b>Year</b></td><td><b>Lenght</b></td><td><b>Lyric</b></td><td><b>Desc</b></td><td><b>Genre</b></td></thead>__list__</table><hr /><h3>Extra info</h3><table style="width:100%"><thead><td><b>Title</b></td><td><b>Encoded</b></td><td><b>Copyright</b></td><td><b>Publisher</b></td><td><b>OriginalArtist</b></td><td><b>URL</b></td><td><b>Comments</b></td><td><b>Composer</b></td></thead>__list2__</table></div>
</body>
</html>

I prepared 2 tables to display ID3 infos of each enumerated file

我准备了2个表格来显示每个枚举文件的ID3信息

步骤2. CSS (Step 2. CSS)

Here are used CSS styles:

以下是使用CSS样式:

css / main.css (css/main.css)


body{background-color:#ddd;margin:0;padding:0}
.example{position:relative;background-color:#fff;width:980px;height:700px;border:1px #000 solid;margin:20px auto;padding:20px;-moz-border-radius:3px;-webkit-border-radius:3px}

body{background-color:#ddd;margin:0;padding:0}
.example{position:relative;background-color:#fff;width:980px;height:700px;border:1px #000 solid;margin:20px auto;padding:20px;-moz-border-radius:3px;-webkit-border-radius:3px}

步骤3. PHP (Step 3. PHP)

Our most important part of project – PHP.

我们项目中最重要的部分– PHP。

index.php (index.php)


<?php
// set error reporting level
if (version_compare(phpversion(), '5.3.0', '>=') == 1)error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
elseerror_reporting(E_ALL & ~E_NOTICE);
// gathering all mp3 files in 'mp3' folder into array
$sDir = 'mp3/';
$aFiles = array();
$rDir = opendir($sDir);
if ($rDir) {while ($sFile = readdir($rDir)) {if ($sFile == '.' or $sFile == '..' or !is_file($sDir . $sFile))continue;$aPathInfo = pathinfo($sFile);$sExt = strtolower($aPathInfo['extension']);if ($sExt == 'mp3') {$aFiles[] = $sDir . $sFile;}}closedir( $rDir );
}
// new object of our ID3TagsReader class
$oReader = new ID3TagsReader();
// passing through located files ..
$sList = $sList2 = '';
foreach ($aFiles as $sSingleFile) {$aTags = $oReader->getTagsInfo($sSingleFile); // obtaining ID3 tags info$sList .= '<tr><td>'.$aTags['Title'].'</td><td>'.$aTags['Album'].'</td><td>'.$aTags['Author'].'</td><td>'.$aTags['AlbumAuthor'].'</td><td>'.$aTags['Track'].'</td><td>'.$aTags['Year'].'</td><td>'.$aTags['Lenght'].'</td><td>'.$aTags['Lyric'].'</td><td>'.$aTags['Desc'].'</td><td>'.$aTags['Genre'].'</td></tr>';$sList2 .= '<tr><td>'.$aTags['Title'].'</td><td>'.$aTags['Encoded'].'</td><td>'.$aTags['Copyright'].'</td><td>'.$aTags['Publisher'].'</td><td>'.$aTags['OriginalArtist'].'</td><td>'.$aTags['URL'].'</td><td>'.$aTags['Comments'].'</td><td>'.$aTags['Composer'].'</td></tr>';
}
// main output
echo strtr(file_get_contents('main_page.html'), array('__list__' => $sList, '__list2__' => $sList2));
// class ID3TagsReader
class ID3TagsReader {// variablesvar $aTV23 = array( // array of possible sys tags (for last version of ID3)'TIT2','TALB','TPE1','TPE2','TRCK','TYER','TLEN','USLT','TPOS','TCON','TENC','TCOP','TPUB','TOPE','WXXX','COMM','TCOM');var $aTV23t = array( // array of titles for sys tags'Title','Album','Author','AlbumAuthor','Track','Year','Lenght','Lyric','Desc','Genre','Encoded','Copyright','Publisher','OriginalArtist','URL','Comments','Composer');var $aTV22 = array( // array of possible sys tags (for old version of ID3)'TT2','TAL','TP1','TRK','TYE','TLE','ULT');var $aTV22t = array( // array of titles for sys tags'Title','Album','Author','Track','Year','Lenght','Lyric');// constructorfunction ID3TagsReader() {}// functionsfunction getTagsInfo($sFilepath) {// read source file$iFSize = filesize($sFilepath);$vFD = fopen($sFilepath,'r');$sSrc = fread($vFD,$iFSize);fclose($vFD);// obtain base infoif (substr($sSrc,0,3) == 'ID3') {$aInfo['FileName'] = $sFilepath;$aInfo['Version'] = hexdec(bin2hex(substr($sSrc,3,1))).'.'.hexdec(bin2hex(substr($sSrc,4,1)));}// passing through possible tags of idv2 (v3 and v4)if ($aInfo['Version'] == '4.0' || $aInfo['Version'] == '3.0') {for ($i = 0; $i < count($this->aTV23); $i++) {if (strpos($sSrc, $this->aTV23[$i].chr(0)) != FALSE) {$s = '';$iPos = strpos($sSrc, $this->aTV23[$i].chr(0));$iLen = hexdec(bin2hex(substr($sSrc,($iPos + 5),3)));$data = substr($sSrc, $iPos, 9 + $iLen);for ($a = 0; $a < strlen($data); $a++) {$char = substr($data, $a, 1);if ($char >= ' ' && $char <= '~')$s .= $char;}if (substr($s, 0, 4) == $this->aTV23[$i]) {$iSL = 4;if ($this->aTV23[$i] == 'USLT') {$iSL = 7;} elseif ($this->aTV23[$i] == 'TALB') {$iSL = 5;} elseif ($this->aTV23[$i] == 'TENC') {$iSL = 6;}$aInfo[$this->aTV23t[$i]] = substr($s, $iSL);}}}}// passing through possible tags of idv2 (v2)if($aInfo['Version'] == '2.0') {for ($i = 0; $i < count($this->aTV22); $i++) {if (strpos($sSrc, $this->aTV22[$i].chr(0)) != FALSE) {$s = '';$iPos = strpos($sSrc, $this->aTV22[$i].chr(0));$iLen = hexdec(bin2hex(substr($sSrc,($iPos + 3),3)));$data = substr($sSrc, $iPos, 6 + $iLen);for ($a = 0; $a < strlen($data); $a++) {$char = substr($data, $a, 1);if ($char >= ' ' && $char <= '~')$s .= $char;}if (substr($s, 0, 3) == $this->aTV22[$i]) {$iSL = 3;if ($this->aTV22[$i] == 'ULT') {$iSL = 6;}$aInfo[$this->aTV22t[$i]] = substr($s, $iSL);}}}}return $aInfo;}
}
?>

<?php
// set error reporting level
if (version_compare(phpversion(), '5.3.0', '>=') == 1)error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
elseerror_reporting(E_ALL & ~E_NOTICE);
// gathering all mp3 files in 'mp3' folder into array
$sDir = 'mp3/';
$aFiles = array();
$rDir = opendir($sDir);
if ($rDir) {while ($sFile = readdir($rDir)) {if ($sFile == '.' or $sFile == '..' or !is_file($sDir . $sFile))continue;$aPathInfo = pathinfo($sFile);$sExt = strtolower($aPathInfo['extension']);if ($sExt == 'mp3') {$aFiles[] = $sDir . $sFile;}}closedir( $rDir );
}
// new object of our ID3TagsReader class
$oReader = new ID3TagsReader();
// passing through located files ..
$sList = $sList2 = '';
foreach ($aFiles as $sSingleFile) {$aTags = $oReader->getTagsInfo($sSingleFile); // obtaining ID3 tags info$sList .= '<tr><td>'.$aTags['Title'].'</td><td>'.$aTags['Album'].'</td><td>'.$aTags['Author'].'</td><td>'.$aTags['AlbumAuthor'].'</td><td>'.$aTags['Track'].'</td><td>'.$aTags['Year'].'</td><td>'.$aTags['Lenght'].'</td><td>'.$aTags['Lyric'].'</td><td>'.$aTags['Desc'].'</td><td>'.$aTags['Genre'].'</td></tr>';$sList2 .= '<tr><td>'.$aTags['Title'].'</td><td>'.$aTags['Encoded'].'</td><td>'.$aTags['Copyright'].'</td><td>'.$aTags['Publisher'].'</td><td>'.$aTags['OriginalArtist'].'</td><td>'.$aTags['URL'].'</td><td>'.$aTags['Comments'].'</td><td>'.$aTags['Composer'].'</td></tr>';
}
// main output
echo strtr(file_get_contents('main_page.html'), array('__list__' => $sList, '__list2__' => $sList2));
// class ID3TagsReader
class ID3TagsReader {// variablesvar $aTV23 = array( // array of possible sys tags (for last version of ID3)'TIT2','TALB','TPE1','TPE2','TRCK','TYER','TLEN','USLT','TPOS','TCON','TENC','TCOP','TPUB','TOPE','WXXX','COMM','TCOM');var $aTV23t = array( // array of titles for sys tags'Title','Album','Author','AlbumAuthor','Track','Year','Lenght','Lyric','Desc','Genre','Encoded','Copyright','Publisher','OriginalArtist','URL','Comments','Composer');var $aTV22 = array( // array of possible sys tags (for old version of ID3)'TT2','TAL','TP1','TRK','TYE','TLE','ULT');var $aTV22t = array( // array of titles for sys tags'Title','Album','Author','Track','Year','Lenght','Lyric');// constructorfunction ID3TagsReader() {}// functionsfunction getTagsInfo($sFilepath) {// read source file$iFSize = filesize($sFilepath);$vFD = fopen($sFilepath,'r');$sSrc = fread($vFD,$iFSize);fclose($vFD);// obtain base infoif (substr($sSrc,0,3) == 'ID3') {$aInfo['FileName'] = $sFilepath;$aInfo['Version'] = hexdec(bin2hex(substr($sSrc,3,1))).'.'.hexdec(bin2hex(substr($sSrc,4,1)));}// passing through possible tags of idv2 (v3 and v4)if ($aInfo['Version'] == '4.0' || $aInfo['Version'] == '3.0') {for ($i = 0; $i < count($this->aTV23); $i++) {if (strpos($sSrc, $this->aTV23[$i].chr(0)) != FALSE) {$s = '';$iPos = strpos($sSrc, $this->aTV23[$i].chr(0));$iLen = hexdec(bin2hex(substr($sSrc,($iPos + 5),3)));$data = substr($sSrc, $iPos, 9 + $iLen);for ($a = 0; $a < strlen($data); $a++) {$char = substr($data, $a, 1);if ($char >= ' ' && $char <= '~')$s .= $char;}if (substr($s, 0, 4) == $this->aTV23[$i]) {$iSL = 4;if ($this->aTV23[$i] == 'USLT') {$iSL = 7;} elseif ($this->aTV23[$i] == 'TALB') {$iSL = 5;} elseif ($this->aTV23[$i] == 'TENC') {$iSL = 6;}$aInfo[$this->aTV23t[$i]] = substr($s, $iSL);}}}}// passing through possible tags of idv2 (v2)if($aInfo['Version'] == '2.0') {for ($i = 0; $i < count($this->aTV22); $i++) {if (strpos($sSrc, $this->aTV22[$i].chr(0)) != FALSE) {$s = '';$iPos = strpos($sSrc, $this->aTV22[$i].chr(0));$iLen = hexdec(bin2hex(substr($sSrc,($iPos + 3),3)));$data = substr($sSrc, $iPos, 6 + $iLen);for ($a = 0; $a < strlen($data); $a++) {$char = substr($data, $a, 1);if ($char >= ' ' && $char <= '~')$s .= $char;}if (substr($s, 0, 3) == $this->aTV22[$i]) {$iSL = 3;if ($this->aTV22[$i] == 'ULT') {$iSL = 6;}$aInfo[$this->aTV22t[$i]] = substr($s, $iSL);}}}}return $aInfo;}
}
?>

After put your mp3 files near these code files thats all. Yes, there are a lot of code, but everything is close. Commonly – you can check code in beginning (before defining of class), and class itself. First half is very easy – passing through files of folder, and generating output. So about class itself (ID3TagsReader) – this is more difficult. We will read hex code of each MP3 file and looking for inner information (ID3). I will try to pick all ID3 tags which can be available in Winamp (mp3 player). But I can say that the total of all possible tags is much more.

将您的mp3文件放在这些代码文件附近之后。 是的,有很多代码,但是一切都很接近。 通常-您可以在开始定义类之前检查代码,以及类本身。 上半部分非常简单–遍历文件夹文件并生成输出。 因此,关于类本身(ID3TagsReader)–这更困难。 我们将阅读每个MP3文件的十六进制代码,并查找内部信息(ID3)。 我将尝试选择所有可以在Winamp(mp3播放器)中使用的ID3标签。 但是我可以说所有可能的标签的总数更多。

现场演示

结论 (Conclusion)

I hope today’s article was very interesting for you. This material can be of great interest for projects that work with the music. This will help you get a variety of information from music files without including another large libraries. Good luck in your work!

我希望今天的文章对您来说很有趣。 对于与音乐一起工作的项目,此材料可能会引起极大的兴趣。 这将帮助您从音乐文件中获取各种信息,而无需包括其他大型库。 祝您工作顺利!

翻译自: https://www.script-tutorials.com/id3-tags-reader-with-php/

php 创建临时id

php 创建临时id_使用PHP创建ID3标签阅读器相关推荐

  1. WINDOWSPHONE STUDY1:创建一个 Windows Phone 7 下的简单 RSS 阅读器

    在这篇文章中我们将为 Windows Phone 7 手机创建一个简单的 RSS (Really Simple Syndication) 阅读器.用户界面包含一个文本输入框用于输入 RSS 地址,以及 ...

  2. Go 学习笔记(49)— Go 标准库之 io/ioutil(读写文件、获取目录下的文件和子目录、创建临时目录和文件)

    1. 简要概述 import "io/ioutil" 包 io/ioutil 实现一些 I/O 实用程序函数. 2. 相关函数 2.1 func ReadAll func Read ...

  3. 【C语言刷题】交换两个变量(包含不创建临时变量)的解法

    目录 一.常规方法(引入空瓶变量) 二.题目要求,不允许创建临时变量 2.1 通过两数加法实现交换 2.2 按位异或操作符实现交换 题目:写代码实现两个变量的交换.(不允许创建临时变量) 一.常规方法 ...

  4. linux 创建临时文件目录 mktemp 命令 简介

    目录 1 .语法 2 .选项列表 3 .实例 1 )创建临时文件 2 )创建临时目 3 )在/tmp中创建临时文件 4 )在指定目录下创建临时目录 5 )使用选项-u创建 6 )使用选项-du创建 创 ...

  5. python tempfile 创建临时目录

    一.tempfile介绍 该模块创建临时文件和目录.它适用于所有支持的平台.TemporaryFile,NamedTemporaryFile,TemporaryDirectory,和SpooledTe ...

  6. Qt之QTemporaryDir用法(创建临时目录)

    概述 在 Qt 开发中,有时候会要创建一个临时目录,用于存储一些临时文件,在用完过后又要删除该目录,这个逻辑自己实现起来并不复杂,多写几行代码就搞定了,但是这里要说的是更简单的用法QTemporary ...

  7. [Apple开发者帐户帮助]八、管理档案(2)创建临时配置文件(iOS,tvOS,watchOS)...

    创建临时配置文件以在设备上运行您的应用程序而无需Xcode.在开始之前,您需要一个App ID,一个分发证书和多个注册设备. 有关完整的临时配置文件工作流程,请转到Xcode帮助中的分发到已注册设备( ...

  8. linux 创建临时文件目录 mktemp 命令(创建随机名临时文件)

    创建临时文件或者目录,这样的创建方式是安全的.此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.SUSE.openSUSE.Fedora. 1 .语法 mktemp [ 选项]   ...

  9. 不允许创建临时变量,交换两个数的内容

    不允许创建临时变量,交换两个数的内容 #include <stdio.h> int main(int argc, char *argv[]) { int a = 10, b = 100; ...

  10. Spark创建临时视图

    前言 查看Spark Dataset的API发现,官网给了四种方法来创建临时视图,它们分别是: def createGlobalTempView(viewName: String): Unit // ...

最新文章

  1. 谈谈 Mifare Classic 破解
  2. python中装饰器的作用_Python装饰器详解,详细介绍它的应用场景
  3. .NET与java的MVC模式(3):ASP.NET 页生命周期概述
  4. [更正]谈获取当前系统类型(SP OR PPC)
  5. 自适应lasso_线性回归模型优化算法(Lasso)
  6. 使用layui框架时,在input文本框中显示当前页面时间的方法
  7. java ready()_Java.io.BufferedReader.ready()方法实例
  8. Restrictions查询用法
  9. HDU 6325 Problem G. Interstellar Travel(凸包)
  10. Leetcode 349.两个数组交集(哈希容器unordered_set)
  11. 信息学奥赛一本通 1051:分段函数 | OpenJudge NOI 1.4 13
  12. #9 case while until select语句的运用与例子
  13. OKR目标管理专题及模板大全
  14. 微信小程序 加载 fbx 模型
  15. 苹果无线耳机连接不上_为什么我们一定要买TWS真无线耳机?
  16. 深造分布式 打败面试官 招式三 直捣黄龙
  17. 未婚同居能白头偕老吗
  18. PTA.奇数值结点链表(C语言链表应用)
  19. 【C语言编程--水仙花数II】
  20. Linux---Linux是什么

热门文章

  1. 学习笔记(1):Matlab小白入门必备教程-数据的基本运算
  2. android 清理工具,安卓清理君深度清理软件/真心强
  3. dubbo线程池exhausted
  4. sourceForge, wikipedia与异形
  5. vscode连接服务器
  6. 技术文摘12 yun jia 技术 资料 截图工具 美容
  7. 智遥工作流为SAP节省License实例
  8. Golden Software BLN文件格式
  9. 帆软Report设置参数列表
  10. VMwareESX常用命令和IP地址修改