How to implement relevant search for files (mp3) using PHP?

You need to create a PHP application consisting of two programs: a caching program and a search program. The caching program should examine the given directory with music files on the hard disk, arranged in subdirectories. The result of the study must be saved to a text file so that it can be used by a second program. When examining, it is necessary to determine the file name and its full path in the file system. If the file name contains the recording year of the song, artist, or album, they must be saved separately to a cache file, linked to the music file.
The second program – the search program – should take the name of the composition, artist, year of recording, album as a parameter at startup. The user can enter one or more of the specified criteria. Criteria can be set in whole or in part. For example, when searching for the song “I won’t go Hollywood”, the user can only enter the word “Hollywood”. The program should find entries in the cache file that match the search criteria and show the full path to the found files in the form of a list, arranging the entries in the relevant order.

PS. I did the output of the files, and then a stupor (you need to isolate somehow the names of the song, album, year of recording in the full path, how to do this? As I understand it, separate the full path with slashes, then just go over each line and search. If all the words matched , then assign index 1, if 2 then index 2, etc. I still can’t write the full path to the file, I tried the glob function, but there if the folder had a square bracket at the end, I didn’t recognize it as a folder, I used this trick.


$dir = 'C:\Temp';
foreach (glob("$dir\\*.txt") as $filepath) {
      echo 'short name: ' . basename($filepath) . ' | ';
      echo "full path: $filepath | ";
      echo 'size :' . filesize($filepath) . "\n";
} //

Answer 1, authority 100%

Think about what the format of the filenames themselves might be, given the additional data on the year, album, etc. Write them all possible in some example and think about what they have in common. in these records. For example:
artist_name-song name
artist name_song-na-me
etc.
then, for each entry, to the format, compose a search pattern using the preg* functions (preg_match for example). Work with templates.

Leave a reply

Please enter your comment!
Please enter your name here