Forum Moderators: coopster
$output=readfile($file);
The command works just fine. My problem is I don't want all of the information within the file to display. Two of the lines of information are a phone number (phone) and an email address (email). How do I go about suppressing the phone and email information so it remains in the file, but does not display on the screen?
Thank you for any assistance you may provide.
jambojim
Welcome to WebmasterWorld, btw :)
<?php
$file = fopen("yourfile.txt", "r") or exit("Unable to open file!");
while(!feof($file))
{
$thisLine=fgets($file);
//check $thisLine variable here, either with
//regular expression or strpos to see if this
//line contains email or phone number
// and if not, set $canShowThisLine to true;
if($canShowThisLine)
{
echo $thisLine;
}
}
fclose($file);
?>
Reference: [w3schools.com...]
[webmasterworld.com...]
Check Last Message from jshpro2, you just need to invert his "if" so that if your line matches the regex you dont echo and if it doesnt, you echo.
Now, I am TRULY a newbie at this, so I must admit the solutions provided don't make a lot of sense to me - yet! Can anyone inform me just how I may incorporate their solution in the existing code?
Thanks, again, folks.
jambojim
<?php
//form code for user information input
print "<div align=\"center\">";
print "<p><font size=\"+1\">Database Workshop</font></p>";
print "<table width=\"80%\" border=\"0\">";
print " <tr><td><div align=\"center\">To register for this workshop, please enter your information and click Submit.
</div></td></tr>";
print "<tr><td bgcolor=\"#CCCCCC\"><form name=\"form1\" method=\"post\" action=\"workshop.php\">";
print "<table width=\"100%\" border=\"0\">";
print "<tr><td width=\"44%\"><div align=\"right\">Name:</div></td>";
print "<td width=\"56\"><input type=\"text\" name=\"name\"></td></tr>";
print "<tr><td><p align=\"right\">Email Address:</p></td>";
print "<td><input type=\"text\" name=\"email\"></td></tr>";
print "<tr><td><p align=\"right\">Phone Number:</p></td>";
print "<td><input type=\"text\" name=\"phone\"></td></tr>";
print "<tr><td><div align=\"right\">Comments:</div></td>";
print "<td><textarea name=\"comments\" cols=\"30\" rows=\"4\"></textarea></td></tr>";
print "<tr><td colspan=\"2\"><div align=\"center\">";
print "<input type=\"submit\" name=\"Submit\" value=\"Submit\">";
print "<input type=\"reset\" name=\"reset\" value=\"Reset\"></div></td></tr></table></form></td></tr></table><br></font></div>";
//reads counter from "count.dat" file - will need to be preset to number of students in workshop
$counter_file="count.dat";
if(!($fp=fopen($counter_file,"r"))) die ("Cannot open $counter_file.");
$counter=(int)fread($fp,20);
fclose($fp);
//emails information to myname!@xx.edu
$to="myname@xx.edu";
$subject="New Database Workshop Registration";
$body="$comments";
mail($to,$subject,$body);
//rolls counter down 1 for display purposes
$count=$counter-1;
//gets current date ( Month Day Year)
$date=gmdate("M d Y");
//assign data file "registrants.txt"
$file="registrants.txt";
//if the remaining student counter is above 0, writes registrant info to file formatted for html
if($counter!=0)
{
$fp=fopen($file,"a+");
fwrite($fp,"<div align=\"center\"><table width=\"70%\"><tr><td><hr noshade width=\"60%\"><h3>Registrant #$counter</h3><br><b>Date: </b>$date \n<br><b>Name: </b>$name \n<br> Phone: $phone \n<br> <b>Email: </b><a href=\"mailto:$email\">$email</a> \n<br><br><b>Comments:</b>$comments</font>\n\n<br><hr noshade width=\"60%\"></td></tr></table></div>");
//if there are more than 2 positions left, thanks registrant for registering
if($counter>2)
print "<div align=\"center\"><h2>Thank you for registering, there are $count positions left.</h2></div>";
//if there is only one position left, thanks registrant for registering
elseif($counter==2)
print "<div align=\"center\"><h2>Thank you for registering, there is $count position left.</h2></div>";
//if there are no positions left, thanks registrant for registering
elseif($counter==1)
print "<div align=\"center\"><h2>Thank you for registering, there are no available positions left.</h2></div>";
fclose($fp);
}
//if there are no positions left when submit is clicked, user is notified
else
print "<div align=\"center\"><h2>This workshop is completely full.<br>Please register for another workshop in the future.</h2></div>";
//rolls counter down 1, and writes the new value to the "count.dat" file
if($counter>0)
$counter--;
else
$counter=0;
$fp=fopen($counter_file,"w");
fwrite($fp,$counter);
fclose($fp);
//outputs the contents of the file to the screen
$output=readfile($file);
?>