I am trying to write a php script that will process each line of an m3u file and write it to the corresponding hour file. Whenever the process begins we always start at hour 00 or 12am midnight. Everything from the first line until the line that says END-OF-HOUR goes into file $month$day-$hour.58.15.m3u
$month and $day are to stay constant during this entire process and do successfully. Where I run into my problem is when I hit the END-OF-HOUR line. What is suppose to happen is that the script switches $hour from 00 to 01. The preceding 0 is very important for hours 0-9. Once the switch occurs it will start writing from the next line in the file to the hour 01 file until it hits the END-OF-HOUR line again. Once again increasing in hour value.
This needs to continue for all 24 hours of the day.
What is happening is that this script is copying the master file all into the hour 00 file.
Here is what I was able to do on my own:
<?php
//$location="";
$file="PLAYLIST";
$month="Nov";
$day="28";
$hour="00";
$outputlocation="Processed";
$outputfile="$month$day-$hour.58.15";
//Create Playlist Files Code Here and Working//
$handle = fopen("$file.m3u", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
// process the line read.
//Begin Processing
//If End Of Hour
if ($line=="END-OF-HOUR"){
//If Not 11PM
if ($hour !=="23"){
$hour="$hour" + 1;
}
//If 11PM
if ($hour =="24"){
echo "<script>alert('MusicMaster File Processing Complete')</script>";
}
}
//If Not End Of Hour
if ($line !="END-OF-HOUR"){
$ofile=file_get_contents("$outputlocation\\$outputfile.m3u");
$nfile="$ofile
$line";
file_put_contents("$outputlocation\\$outputfile.m3u", "$nfile");
}
}
fclose($handle);
} else {
// error opening the file.
echo "<script>alert('Error Opening MusicMaster File')</script>";
}
//https://stackoverflow.com/questions/13246597/how-to-read-a-file-line-by-line-in-php
?>
I'm not well versed in looping in php. just very basic if statements and mysql queries.
This is the file it pulls from and outputs to each hour. This is only a snippet:
M:\JINGLES\TOH\LEGAL ID 20170416-A.mp3
M:\ITUNES\Music\Danny Gokey\Rise (Album)\02 If You Ain't In It.mp3
M:\ITUNES\Music\MercyMe\MercyMe, It's Christmas\06 Have a Holly Jolly Christmas.mp3
M:\JINGLES\STANDARD\Stay Tuned.mp3
M:\ITUNES\Music\Royal Tailor\Royal Tailor\06 Ready Set Go.mp3
M:\ITUNES\Music\Third Day\Revelation\03 Call My Name.mp3
M:\THE STORY BEHIND IT\Mandisa - Bleed The Same (Song Story).mp3
M:\PROMOTIONS\Valley Park Flea Market & Resale (6PM 5-29).mp3
M:\PROMOTIONS\FoundationLyrics_com.mp3
M:\PROMOTIONS\VinVlogger_com (5-15-17).mp3
END-OF-HOUR
M:\JINGLES\TOH\LEGAL ID 20170816.mp3
M:\ITUNES\Music\Audio Adrenaline\Kings & Queens\02 Kings & Queens.mp3
M:\ITUNES\Music\Stars Go Dim\Stars Go Dim\01 Doxology.mp3
M:\JINGLES\STANDARD\LIN\LIN-002.mp3
M:\ITUNES\Music\NewSong\Newsong\Christian.mp3
M:\ITUNES\Music\David Dunn\Crystal Clear - EP\02 Have Everything.m4a
M:\THE STORY BEHIND IT\Mandisa - Bleed The Same (Song Story).mp3
M:\PROMOTIONS\Valley Park Flea Market & Resale (6PM 5-29).mp3
END-OF-HOUR
I know I'm doing something wrong and just can't seem to figure out what it is. Any help you can provide would be very much appreciated.