使用PHP从.mp3s读取/添加ID3标签到HTML
After doing some research, I found this link to a "guide" on PHP: ID3 Functions. I'm not quite sure how to go about implementing this into a website so that:
- Finds all .mp3's in a folder
- Reads the ID3 tags from the file (Artist, year, etc.)
- Allows me to put the ID3 tags along with a link to the file on an HTML website
I already have the finding all .mp3's in a folder working, but I'm not sure how to implement the ID3 functions to read from those files.
在做了一些研究后,我发现这个链接指向PHP上的“指南”: ID3功能。 我不太确定如何将其实现到网站中,以便: p>
- 查找文件夹中的所有.mp3 li>
- 从文件中读取ID3标签(艺术家,年份等) li>
- 允许我将ID3标签与指向该文件的链接放在
HTML网站上 li>
我已经找到了所有.mp3在一个文件夹中的工作,但我不知道如何实现ID3函数来读取这些文件。 p> div >
Easiest way would probably be id3_get_tag($filename, $version)
.
Just provide a string containing the file path and optionally a ID3 Tag version (leave out if you don't know):
$files = array('/folder/file1.mp3', '/folder/file2.mp3');
$tags = array();
foreach($files as $file) {
$tags[$file] = id3_get_tag($file);
// convert genre:
if(array_key_exists('genre', $tags[$file]) && is_integer($tags[$file]['genre'])
&& $tags[$file]['genre'] >= 0 && $tags[$file]['genre'] <= 147) {
$tags[$file]['genre'] = id3_get_genre_name($tags[$file]['genre']);
}
}
$tags
will then be an array like this:
['/folder/file1.mp3'] = array('interpret' => 'John Doe', 'title' => 'PHP is cool', 'genre' => 'Techno')
['/folder/file2.mp3'] = array('interpret' => 'Jane Doe', 'title' => 'ASP is low', 'genre' => 'House')
What keys you actually get from this, depends on the ID3 version of each .mp3 file and the actual content (whatever someone wrote into that file).