How to Use php to extract information from mp3 files

Source: Internet
Author: User

Today, I saw a small software from Han Yu studio, which can extract mp3 file information under the specified directory and generate a webpage. The function is very simple, but it is very practical, so I thought that I could use php to implement this function, so I went to work.
We first open several mp3 files in a text editor. Although all the files are garbled, we find that there is a TAG at the last point, followed by various information about the mp3 file, including the artist, album name, time, and some website information (of course, some files do not exist. You can use winamp to add the album. The details are not described.) Haha, I feel very good, the next step is how to extract the information.
Before extracting information, we need to find the mp3 file in the specified directory. The following is the code snippet for extracting the mp3 file:
$ Thisdir = dir (".");
While ($ file = $ thisdir-> read ()){
If ((! Is_dir ("./$ file") and ($ file! = ".") And ($ file! = ".."))
{
$ Mp3 = strstr ($ file ,".");
If ($ mp3 = ". mp3 "){
Echo"

  • $ File
  • ";
    Echo "";
    }
    }
    This code can display the mp3 file in the specified directory (the directory of the file to be saved in the example ).
    The next step is to extract the information from the extracted mp3 file. The following is a program snippet:
    $ Fp = fopen ($ file, "r ");
    $ Content = fread ($ fp, filesize ($ file ));
    $ Content = strstr ($ content, "TAG ");
    Echo "$ content ";
    Because the Information starts with a TAG string, we use the strstr function to find the first tag to appear, and then display the subsequent string. This is the information in the mp3 file. Of course, this information is messy. You can use the string function to analyze and process the extracted information to obtain useful information. The specifics are left for the readers to think about.

    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.