Help finalizing this code.
Posted: Wed Dec 22, 2004 11:21 am
Can someone help me with this I am new to php but trying to get a simple email system set up. I don't have many addresses so I am using a text file to store the information.
My text file is in the following format.
Firstname|Lastname|Email|Account|Accountid
Randy|Jackson|rjackson@yahoo.com|active|12345
Jim|Howard|jimhow@msn.com|active|12346
I need to extract the fields individually starting with line 1 not 0.
Here is what I have so far but I cannot seem to get the information by looping properly.
<?php
$SEP="|";
$dbfile = "mytextfile.txt";
$contents = file($dbfile);
//Take out the line feeds at the ends of the array
for ($i=0;$i<count($contents);$i++) {$contents[$i] = trim($contents[$i]);}
for($i=1;$i<count($contents);$i++){
if(eregi("^".$SEP,$contents[$i])){$loc = $i;
$tmp = explode($SEP,$contents[$loc]);
echo $tmp[$i]."<br>";
echo $i."<br>";
}
}
?>
I am just outputing the information to the screen right now for testing. But what it is doing is giving me one piece of information on each line in the file.
The output should be as such
Randy
Jackson
rjackson@yahoo.com
active
12345
Jim
Howard
jimhow@msn.com
active
12346
Can someone help me finish this up. I have spent a couple of days on this and seem to just be running around in circles.
Any and all help is greatly appreciated.
Thanks,
remasters
My text file is in the following format.
Firstname|Lastname|Email|Account|Accountid
Randy|Jackson|rjackson@yahoo.com|active|12345
Jim|Howard|jimhow@msn.com|active|12346
I need to extract the fields individually starting with line 1 not 0.
Here is what I have so far but I cannot seem to get the information by looping properly.
<?php
$SEP="|";
$dbfile = "mytextfile.txt";
$contents = file($dbfile);
//Take out the line feeds at the ends of the array
for ($i=0;$i<count($contents);$i++) {$contents[$i] = trim($contents[$i]);}
for($i=1;$i<count($contents);$i++){
if(eregi("^".$SEP,$contents[$i])){$loc = $i;
$tmp = explode($SEP,$contents[$loc]);
echo $tmp[$i]."<br>";
echo $i."<br>";
}
}
?>
I am just outputing the information to the screen right now for testing. But what it is doing is giving me one piece of information on each line in the file.
The output should be as such
Randy
Jackson
rjackson@yahoo.com
active
12345
Jim
Howard
jimhow@msn.com
active
12346
Can someone help me finish this up. I have spent a couple of days on this and seem to just be running around in circles.
Any and all help is greatly appreciated.
Thanks,
remasters