That method does work, but there’s one more issue, that is separating the text file with “;”’s. Let me explain the whole process, which works in 3 pages.
Page One:
There is a form, with a text box for show title input and allows the user to select their show time from a drop down. They hit submit, the title and time are parsed to second page.
Page Two:
The script below appends the text file with their new show title. If it was successful, the script outputs “Write test was successful!” and gives them a link to the 3rd page (not in code below).
$time = @$_POST["time"];
$test = @$_POST["show_title"];
$find = $time;
$replace = $test;
$filename = "shows2.radio2x";
if ($fd = @fopen($filename, "r+")) {
$contents = ereg_replace("$find ([^\n]*)\n", "$find $replace\n", fread($fd, filesize($filename))."\n");
rewind($fd); if (!@fwrite($fd, $contents)) { echo "Error writing to file"; }
fclose($fd);
echo "Write test was successful!";
}
else { die("Could not open $filename for reading and writing");
}
Third Page:
Where your code comes in, it shows the user that they have successfully entered in their data with proof.
$time = "4-6pm";
$fLines = file("shows2.radio2x");
foreach($fLines as $myLine){
$expVals = explode(";",$myLine);
if ($time == $expVals[0]) {
echo trim($expVals[1]);
}
}
I know this is rocky, and I probably will combine these functions, but for testing and learning sake, I would like to use three pages. The problem, as you might see, is having the text file separated like this:
4-6pm; User’s show title
The “;” will interfere with the code on page two (especially if they change titles several times). Is there another way to have the code on page 3 with out using the “;” deliminator? I tried “ ” but then it only echoes the first word in the show title. Once again thanks very much for your help. 😃