PHP's Music ID3 extension

Source: Internet
Author: User
Tags id3

Do not know if you have this experience, some downloaded from the Internet MP3 Music, the file name is clearly 01, 02 such a serial number, but the play can show the correct name of the song, is it a bit strange?

This is actually ID3 in the dark.

ID3, typically located in a number of bytes at the beginning or end of a MP3 file, is appended with information about the MP3 's singer, title, album name, age, style, and so on, which is known as ID3 information, ID3 information is divided into two versions, V1 and V2 editions. Where: V1 version of the ID3 at the end of the MP3 file 128 bytes, starting with the tag three characters, followed by the song information. V2 version is generally located at the beginning of MP3, can store lyrics, the album's Pictures and other large-capacity information.

Okay, here's the background.

PHP ID3 extension is provided by PECL, the main use by, get and set MP3 audio file ID3 information, including the MP3 singer, title, album name, age, style, notes

1. Install the ID3 extension " http://pecl.php.net/package/id3."

 wget http://pecl.php.net/get/id3-0.2.tgz

 Tar zxvf id3-0.2.tgz

CD id3-0.2.tgz

./configure--with-php-config=/usr/local/php/bin/php-config

Make && make install

PS: I made an error on this side,  id3.c:196:1: error: unknown type name ' Function_entry ', workaround, id3.c file 196 lines of Function_entry change to Zend_function_ Entry can do it.

Then add the compiled extension file to the php.ini id3.so

Restart the service, you can see the ID3 extension information in Phpinfo

2. Function usage

First we find a MP3 resource

The ID3 extension provides a total of 9 functions

Id3_?get_?frame_?long_?name//No Research

Id3_?get_?frame_?short_?name//No Research

Id3_?get_?genre_?id (genre_name)//Get style ID by style name

Id3_?get_?genre_?list (void)//list all style key Values table

Id3_?get_?genre_?name (genre_id)//Get style name by Style ID

Id3_?get_?tag (filename)//Get tag information for mp3

Id3_?get_?version (void)//Get ID3 extension version number

Id3_?remove_?tag (filename)//delete MP3 's tag information

Id3_?set_?tag (filename,tags)//Set tag information for MP3

3. Code examples

<?PHP$filename= ' 4007108962.mp3 ';$tag= Id3_get_tag ($filename);Var_dump($tag);//Array (5) {["title"]=>string (0) "" ["Artist"]=>string (2) "??" ["album"]=>string (0) "" ["comment"]=>string (0) "" ["Genre"]=>int (255)}$version= Id3_get_version ($filename);Echo $version;//1$tags=Array(' title ' = ' + ' headline ', ' Artist ' = ' Author ', ' album ' = ' album ', ' Year ' + ', ' genre ' =>8, ' comment ' + ' reviews, up to 30 bytes ‘);$set= Id3_set_tag ($filename,$tags);Var_dump($set);//true$genre _name= Id3_get_genre_name ($tag[' Genre ']);Var_dump($genre _name);//Jazz$genre _id= id3_get_genre_id (' Jazz ');Var_dump($genre _id);//8$remove= Id3_remove_tag ($filename);Var_dump($remove);//true$list=id3_get_genre_list ();Var_dump($list);//Array ([0] = Blues [1] = Classic rock[2] = Country [3] = = Dance ... [147] = synthpop)

PHP's Music ID3 extension

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.