Page 1 of 1

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

Posted: Wed Apr 24, 2002 2:01 pm
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

Posted: Wed Apr 24, 2002 4:59 pm
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

Posted: Thu Apr 25, 2002 12:31 pm
by romeo
figured that much, my exerience is limite dto hacking scripts.. so im dumb when getting stuff started...
thanks tho

okay.. almost there.. i think

Posted: Thu Apr 25, 2002 10:42 pm
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

Posted: Fri Apr 26, 2002 11:53 am
by romeo
okay maybe im a fruit... is that why it's so quiet around here ? :)

Posted: Fri Apr 26, 2002 1:00 pm
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

Posted: Fri Apr 26, 2002 3:34 pm
by romeo
Sam you rule,
i havent figured out what to do with it yet, but you rule

Posted: Fri Apr 26, 2002 3:53 pm
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

Posted: Fri Apr 26, 2002 5:55 pm
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

Posted: Fri Apr 26, 2002 6:59 pm
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.

Posted: Fri Apr 26, 2002 7:34 pm
by romeo
same thing.. completely blank...

I'll read some more...

if you wanna see it http://www.jeepsunpaved.com/text/index.php

Posted: Fri Apr 26, 2002 7:39 pm
by romeo
maybe its something ghay on my server?

Posted: Sun Apr 28, 2002 1:43 am
by romeo
oranges
bananas
apple
fruit

sam