Make your own free website on

Visit the Official PHP Website

Search this Site

PHP Programming

By James N Hitz

The Code Explained: Displaying the Mailing List

As already said. This section illustrates how we can list the contents of the data file. Be wary of how this code is used because some sneaky guys may Spam your subscribers.

The listing code attacks the problem head-on by first of all attempting to open the datafile...

$dfHandle = fopen($datafile,'r') or die("Internal Error.  Cannot open data file");
... and printing the heading part of the mailing list - a table's preamble:
echo "<h3>Current Subscriptions to the PHP Mailing List</h3>";
echo "<table width=\"100%\" bgcolor=\"#FFFFCC\" border cellspacing='0' cellpadding='3'>\n".
"<tr bgcolor='#FFCC99'><td>First Name</td><td>Last Name</td><td>Email Address</td></tr>";

The entire file is then read into an array and stepped through, splitting each line at the pipe (|) to create an(other) array:

$allFile = file($datafile);
while(list($linenum, $line)= each($allFile)){
	$items = preg_split("/\|/",$line);
	print "<tr><td>$items[0]</td><td>$items[1]</td><td>$items[2]</td></tr>\n";

Finally, the table is closed:

echo "</table>";

Well. That is all as far as our example is concerned. It only needs a little tweaking to convert it into a top-notch mailing list PHP program. I believe that anything can always be made better. I'll let you ponder on that. We are not through with file management yet. That was just an example. Let's proceed and learn some more.

<< Code Explanation: Un-Subscribe | File Tests >>

JamHitz Productions