dsnpjz6907 2013-05-08 01:04
浏览 76
已采纳

使用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.

  • 写回答

1条回答 默认 最新

  • duadlkc5762218 2013-05-08 01:14
    关注

    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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog