im not a fruit, just pressed for time...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

im not a fruit, just pressed for time...

Post by romeo »

And frankly you guys rule...

second problem; that i have been unsuccessful at...

have a huge text file that has 20000 lines in it in the format of

useremail, password, name
user1, password, name &stuff
jim@walrii.com, password, name..
user4, password, name...

Is there a way to go thru it line by line and grab anything that looks like an email address and output it to a file in mail-able format... ie jim@ie.com;walrus@npole.net;etc@etc.etc ...

I'll love you for life
User avatar
enygma
Site Admin
Posts: 175
Joined: Fri Apr 19, 2002 8:29 am
Location: Dallas, Tx

Post by enygma »

regular expressions would be the way to go on this one....
split each line on the comma "," and then look at the values....

there's a regexp on the PHP site (I think) that matches valid email for you pretty well.

-enygma
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

figured that much, my exerience is limite dto hacking scripts.. so im dumb when getting stuff started...
thanks tho
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

okay.. almost there.. i think

Post by romeo »

Having a tough time pushing this one...
this looks right to me...
but im getting the error

Warning: Unknown modifier '+' in /usr/local/apache/htdocs/www/test/index.php on line 11
Array

Code: Select all

<?
$filename = "/usr/local/apache/htdocs/www/test/westol.txt";

$myfile = fopen($filename,"r+") or die("fopen failed");

$contents = fread($myfile, filesize($filename)); 

$pattern = ".+@.+..";
$pattern1 = "(&#1111;a-zA-z0-9]+&#1111;.+-]?)+@(&#1111;a-zA-z0-9+-]+.)+(&#1111;a-zA-Z]&#123;2,3&#125;)";

preg_match_all($pattern1, $contents, $emails);

echo "$emails";

fclose($myfile);
?>
Thanks guys I appreciate the help
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

okay maybe im a fruit... is that why it's so quiet around here ? :)
User avatar
sam
Forum Contributor
Posts: 217
Joined: Thu Apr 18, 2002 11:11 pm
Location: Northern California
Contact:

Post by sam »

First this is a very bad idea:

Code: Select all

$contents = fread($myfile, filesize($filename));
If you file is 20,000 lines long this will tare your webserver a new one. Use the folowing funtions:

Code: Select all

while ($userinfo = fscanf ($fp, "%s,%s,%s
")){
   //... do some stuff with your data
}
This will greatly reduce the memory usage and is far less cpu intensive.

btw here is the php man for fscanf
http://www.php.net/manual/en/function.fscanf.php

Cheers Sam
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

Sam you rule,
i havent figured out what to do with it yet, but you rule
User avatar
sam
Forum Contributor
Posts: 217
Joined: Thu Apr 18, 2002 11:11 pm
Location: Northern California
Contact:

Post by sam »

hehe thanks :oops:

You could do something like this:

Code: Select all

$fp = fopen("your_file","r");
$i=0;
while ($userinfo = fscanf ($fp, "%s,%s,%s
"))&#123; 
   // The array $userinfo now contains one row from your text file
   // (pending that there are no formating error in it)
   if(ereg("&#1111;:alnum:]*@&#1111;:alnum:]*&#1111;.]&#1111;a-zA-Z0-9.]&#123;2,6&#125;",$userinfo&#1111;0]))&#123;
       $email&#1111;$i++] = $userinfo&#1111;0];
   &#125;
&#125;
You now have an array $email that contains all the email address that are syntheticly valid.
I must go now, time to reinstall IE6.

Cheers Moe
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

hmm
i tried that, i got no errors, but no results either...

the page was entirely blank... (even the source)


Code: Select all

<?
$filename = "/usr/local/apache/htdocs/www/test/westol.txt";

$fp = fopen($filename,"r"); 
$i=0; 
while ($userinfo = fscanf ($fp, "%s,%s,%s
"))&#123; 
   // The array $userinfo now contains one row from your text file 
   // (pending that there are no formating error in it) 
   if(ereg("&#1111;:alnum:]*@&#1111;:alnum:]*&#1111;.]&#1111;a-zA-Z0-9.]&#123;2,6&#125;",$userinfo&#1111;0]))&#123; 
       $email&#1111;$i++] = $userinfo&#1111;0]; 

echo $email&#1111;$i];
   &#125; 
&#125; 

?>
I even made sure i put a samrules@hisplace.com

to check it
User avatar
sam
Forum Contributor
Posts: 217
Joined: Thu Apr 18, 2002 11:11 pm
Location: Northern California
Contact:

Post by sam »

try both:

Code: Select all

$userinfo = fscanf ($fp, "%s
"))&#123;
and adding a different expression, that one has never been tested I might have put an error in it.
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

same thing.. completely blank...

I'll read some more...

if you wanna see it http://www.jeepsunpaved.com/text/index.php
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

maybe its something ghay on my server?
romeo
Forum Contributor
Posts: 138
Joined: Sun Apr 21, 2002 12:50 pm

Post by romeo »

oranges
bananas
apple
fruit

sam
Post Reply