id3_get_tag

(PECL id3 >= 0.1)

id3_get_tagGet all information stored in an ID3 tag

Description

array id3_get_tag ( string $filename [, int $version = ID3_BEST ] )

id3_get_tag() is used to get all information stored in the id3 tag of the specified file.

Parameters

filename

The path to the MP3 file

Instead of a filename you may also pass a valid stream resource

version

Allows you to specify the version of the tag as MP3 files may contain both, version 1.x and version 2.x tags

Since version 0.2 id3_get_tag() also supports ID3 tags of version 2.2, 2.3 and 2.4. To extract information from these tags, pass one of the constants ID3_V2_2, ID3_V2_3 or ID3_V2_4 as the second parameter. ID3 v2.x tags can contain a lot more information about the MP3 file than ID3 v1.x tags.

Return Values

Returns an associative array with various keys like: title, artist, ..

The key genre will contain an integer between 0 and 147. You may use id3_get_genre_name() to convert it to a human readable string.

Examples

Example #1 id3_get_tag() example

<?php
$tag 
id3_get_tag"path/to/example.mp3" );
print_r($tag);
?>

The above example will output something similar to:

Array
(
    [title] => DN-38416
    [artist] => Re:\Legion
    [album] => Reflections
    [year] => 2004
    [genre] => 19
)

Example #2 id3_get_tag() example

<?php
$tag 
id3_get_tag"path/to/example2.mp3"ID3_V2_3 );
print_r($tag);
?>

The above example will output something similar to:

Array
(
    [copyright] => Dirty Mac
    [originalArtist] => Dirty Mac
    [composer] => Marcus Götze
    [artist] => Dirty Mac
    [title] => Little Big Man
    [album] => Demo-Tape
    [track] => 5/12
    [genre] => (17)Rock
    [year] => 2001
)

See Also

Коментарии

Автор:
An alternative to this is

<?php
function readID3($filename)
{
   
$mp3 $filename;
   
$genre_arr = array("Blues""Classic Rock""Country""Dance""Disco""Funk""Grunge""Hip-Hop""Jazz""Metal""New Age""Oldies""Other""Pop""R&B""Rap""Reggae""Rock""Techno""Industrial""Alternative""Ska""Death Metal""Pranks""Soundtrack""Euro-Techno""Ambient""Trip-Hop""Vocal""Jazz+Funk""Fusion""Trance""Classical""Instrumental""Acid""House""Game""Sound Clip""Gospel""Noise""AlternRock""Bass""Soul""Punk""Space""Meditative""Instrumental Pop""Instrumental Rock""Ethnic""Gothic""Darkwave""Techno-Industrial""Electronic""Pop-Folk""Eurodance""Dream""Southern Rock""Comedy""Cult""Gangsta""Top 40""Christian Rap""Pop/Funk""Jungle""Native American""Cabaret""New Wave""Psychadelic""Rave""Showtunes""Trailer""Lo-Fi""Tribal""Acid Punk""Acid Jazz""Polka""Retro""Musical""Rock & Roll""Hard Rock""Folk""Folk-Rock""National Folk""Swing""Fast Fusion""Bebob""Latin""Revival""Celtic""Bluegrass""Avantgarde""Gothic Rock""Progressive Rock""Psychedelic Rock""Symphonic Rock""Slow Rock""Big Band""Chorus""Easy Listening""Acoustic""Humour""Speech""Chanson""Opera""Chamber Music""Sonata""Symphony""Booty Bass""Primus""Porn Groove""Satire""Slow Jam""Club""Tango""Samba""Folklore""Ballad""Power Ballad""Rhythmic Soul""Freestyle""Duet""Punk Rock""Drum Solo""Acapella""Euro-House""Dance Hall");
   
$filesize filesize($mp3);
   
$file fopen($mp3"r");
   
fseek($file, -128SEEK_END);
   
$tag fread($file3);
    if(
$tag == "TAG")
    {
       
$data["Song"] = fread($file30);
       
$data["Artist"] = fread($file30);
       
$data["Album"] = fread($file30);
       
$data["Year"] = fread($file4);
       
$data["Comment"] = fread($file30);
       
$data["Genre"] = $genre_arr[ord(fread($file1))];
       
    }
    else
        return(
"MP3 file does not have any ID3 tag!");
   
fclose($file);
    while(list(
$key$value) = each($data))
    {
        echo(
"$key: $value<br>\r\n");   
    }
}
?>

It's a bit more code but does the job fine.

    Поддержать сайт на родительском проекте КГБ