ID3 functions in PHP allow users to manipulate and read ID3 tags. The ID3 tags are part of MP3 and other compressors where files metadata is stored. These ID3 functions are therefore used in MP3 files to store songs along with the information of album, genre, year and track number.

ID3 predefined tags

Some ID3 predefined functions are:

ID3_V1_0 (integer) - It is used when working with ID3 V1.0 tags. These tags may contain the field’s title, artist, album, genre, year and comment.

ID3_V1_1 (integer) - It is used when working with ID3 V1.1 tags. These tags may all information contained in v1.0 tags plus the track number.

  • ID3_V2_1 (integer) - It is used if you are working with ID3 V2.1 tags.
  • ID3_V2_2 (integer) - It is used if you are working with ID3 V2.2 tags.
  • ID3_V2_3 (integer) - It is used if you are working with ID3 V2.3 tags.
  • ID3_V2_4 (integer) - It is used if you are working with ID3 V2.4 tags.
  • ID3_BEST (integer) - It is used if would like to let the id3 functions determine which tag version should be used.

ID3 functions

id3_get_genre_name() 

This function gets the name for a genre id. For example:

<?php
    $genre = id3_get_genre_name(3);
    echo $genre;
?>

id3_get_version() 

This function gets the version of an ID3 tag. 

Example with id3_get_version() in PHP

<?php
    $version = id3_get_version("path/audio_file.mp3");
    
    if($version & ID3_V1_0)
    {
        echo "File contains a 1.x tag";
    }
    
     if($version & ID3_V1_1)
    {
        echo "File contains a 1.1 tag";
    }
    
     if($version & ID3_V1_2)
    {
        echo "File contains a 1.2 tag";
    }
?>

id3_get_genre_list() 

This function gets all the possible genre values. For example:

<?php
    $genres = id3_get_genre_list();
    print_r($genres);
?>

id3_get_genre_id()

This function gets the id of a genre. For example:

<?php
    $id = id3_get_genre_id("Genre example");
    echo $id;
?>

id3_get_frame_long_name() and id3_get_frame_short_name()

These functions get the long and the short name respectively of an ID3v2 frame. For example:

<?php
    $short_name = id3_get_frame_short_name("TITLE NAME");
    echo $short_name;
   
    $long_name = id3_get_frame_long_name("TITLE NAME");
    echo $long_name;
?>

 

›› go to examples ››