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. Open several mp3 files in a text editor, although SyntaxHighlighter. all ();
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.