Water Garden Vista
2013-11-26 07:07:42 UTC
if ($handle = opendir('music')) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != "..") {
echo $i, "
";
echo "$entry\n";
preg_match("/^[A-Za-z0-9 -_ ]*(?= -)/", $entry, $matches);
$artist = $matches[0];
echo $artist;
echo "
";
preg_match("/(?<=- )[A-Za-z0-9().&-', _ ]*(?=.mp3)/", $entry, $matches);
$song = $matches[0];
echo $song;
mysql_query("INSERT INTO songs (song, artist) VALUES ('$song', '$artist')");
$song and $artist always echo but sometimes it does not insert into the database and sometimes it does. Most of the time it does.
I have song and artist set in combination to be a UNIQUE field but even if it is a song or artist that is all unique it still sometimes refuses to write it to my database. It's doing this with about 2 to 4 percent of the songs.
I've taken care of the apostrophes. Even with that thought, it's not the apostrophes that are being skipped. For example, the file "Carpenters - Every Sha La La.mp3" will not be saved in the database even though it will echo the artist "Carpenters" and echo the song "Every Sha La La".