Forum Moderators: coopster

Message Too Old, No Replies

How can i getch all the email addresses from this file

and store it as a global variable

         

laura2k

12:41 pm on Jun 9, 2004 (gmt 0)



Hi,

I have a users.php file that contains all my user details. Each line is for each customer. Each customer also has a email address, i want to fetch all the email addresses and store it as a variable so that i can use it in the BCC field of a form2mail. Can anyone please help me out.

The email address is not the first value on each line. The first value is username, then password, then access level, then the email address. However, the email address starts straight after the following:

<del>0<del>

and it ends with a <del>

so a email address will look like this:

<del>0<del>me@mydomain.com<del>

and then it continues with other values.

can anyone please tell me how i can do this.

Many thanx in advanced.

Laura

jatar_k

4:34 pm on Jun 9, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



maybe try this

1. open the file [ca.php.net]
2. use a while loop [ca.php.net] to read a line from the file using fgets [ca.php.net]
3. use split [ca.php.net] or preg_split [ca.php.net] to chop the lines on '<del>'
4. from the resulting array grab the appropriate value and drop it into your email list or var

output it to somewhere, file, screen, whatever. Then keep the script for next time.

lindajames

5:08 pm on Jun 9, 2004 (gmt 0)

10+ Year Member



sounds gr8

laura2k

5:31 pm on Jun 9, 2004 (gmt 0)



Thanx jatar_k

But it sounds a bit complicated, can anyone simplify it further, i've got a form2mail script ready i just need to take the email addresses out and store them into a variable seperated by commas.

Many thanx in advanced.

jatar_k

7:41 pm on Jun 9, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



it's only 6 lines of code

$fp = fopen('/path/to/file.txt','r'); 
while ($newline = fgets($fp)) {
$linearr = split('<del>',$newline);
$theemails .= $linearr[3] . ",";
}
$theemails = substr($theemails, 0, -1);
echo $theemails;

<added>ok, 7 since I added the substr line

laura2k

11:13 pm on Jun 9, 2004 (gmt 0)



i tried that but i am getting an error saying:

Warning: Wrong parameter count for fgets()

Any ideas?

Thanx

jatar_k

11:33 pm on Jun 9, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



version thing, it is supposed to be optional

fgets($fp,10240)

laura2k

12:01 am on Jun 10, 2004 (gmt 0)



Thanx Jatar, that worked. but how comes the actual variable begins with a comma?

jatar_k

12:02 am on Jun 10, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



blank line or empty email on the first line of the file?

laura2k

12:22 am on Jun 10, 2004 (gmt 0)



yeah first line has comments used for another script

jatar_k

1:56 am on Jun 10, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



$fp = fopen('/path/to/file.txt','r'); 
$nofirstline = true;
while ($newline = fgets($fp,10240)) {
if ($nofirstline) {
$nofirstline = false;
continue;
}
$linearr = split('<del>',$newline);
$theemails .= $linearr[3] . ",";
}
$theemails = substr($theemails, 0, -1);
echo $theemails;