How to extract an email-address from a text file

This is a discussion on How to extract an email-address from a text file within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi people: Can somebody show me a quick code snippet to reliably extract an email-address form a text file ? ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-01-2004
Jerry
 
Posts: n/a
Default How to extract an email-address from a text file

Hi people:

Can somebody show me a quick code snippet to reliably extract an
email-address form a text file ?

Any help greatly appreciated!
Jerry
Reply With Quote
  #2 (permalink)  
Old 08-02-2004
James Smith
 
Posts: n/a
Default Re: How to extract an email-address from a text file

Jerry wrote:

>Hi people:
>
>Can somebody show me a quick code snippet to reliably extract an
>email-address form a text file ?
>
>Any help greatly appreciated!
>Jerry
>
>

Are you a Spammer?
Reply With Quote
  #3 (permalink)  
Old 08-02-2004
eclipsboi
 
Posts: n/a
Default Re: How to extract an email-address from a text file

On Mon, 02 Aug 2004 17:20:25 +1000, James Smith
<jncsmith@optusnet.com.au> wrote:

>Jerry wrote:
>
>>Hi people:
>>
>>Can somebody show me a quick code snippet to reliably extract an
>>email-address form a text file ?
>>
>>Any help greatly appreciated!
>>Jerry
>>
>>

>Are you a Spammer?

If he was, do you think he'd admit to it?
Reply With Quote
  #4 (permalink)  
Old 08-02-2004
Gary L. Burnore
 
Posts: n/a
Default Re: How to extract an email-address from a text file

On Sun, 01 Aug 2004 23:03:30 +0200, Jerry <submitstuff@lycos.com>
wrote:

>Hi people:
>
>Can somebody show me a quick code snippet to reliably extract an
>email-address form a text file ?



Get a pen and a piece of paper. Read the text file. Read and weite
down the email address.


BTW, did you ear a Korean firm just bought Lycos? Hahahahahahaha.
They've got YOUR number.
Reply With Quote
  #5 (permalink)  
Old 08-03-2004
Nikolai Chuvakhin
 
Posts: n/a
Default Re: How to extract an email-address from a text file

Jerry <submitstuff@lycos.com> wrote in message
news:<vemqg091o1raraqn7edv3k0q1p202cuj1p@4ax.com>. ..
>
> Can somebody show me a quick code snippet to reliably extract an
> email-address form a text file ?


Here's a lazy (as in "too lazy to learn regular expressions") one:

function get_addresses($file) {
$breaking = array(' ', ',', '>', '<', "\t", "\r", "\n");
$addr = array();
$data = explode('@', file_get_contents($file));
// Alternative for PHP < 4.3.0:
// $data = explode('@', implode('', file($file)));
$n = count($data);
for ($i = 1; $i < $n; $i++) {
$addr[$i-1] = '@';
$begin = 0;
$end = strlen($data[$i-1]) - 1;
while ((!in_array($data[$i-1]{$end}, $breaking)) and ($begin <= $end)) {
$addr[$i-1] = $data[$i-1]{$end} . $addr[$i-1];
$end--;
}
$begin = 0;
$end = strlen($data[$i]) - 1;
while ((!in_array($data[$i]{$begin}, $breaking)) and ($begin <= $end)) {
$addr[$i-1] .= $data[$i]{$begin} ;
$begin++;
}
}
if (count($addr) == 0) {
return FALSE;
} else {
return $addr;
}
}

This function returns an array including all e-mail addresses found
in the $file or FALSE if no address is found.

Cheers,
NC
Reply With Quote
  #6 (permalink)  
Old 08-03-2004
eclipsboi
 
Posts: n/a
Default Re: How to extract an email-address from a text file

On 3 Aug 2004 15:09:06 -0700, nc@iname.com (Nikolai Chuvakhin) wrote:

>This function returns an array including all e-mail addresses found
>in the $file or FALSE if no address is found.
>
>Cheers,
>NC


You do realize you probably just doubled the junk mail in all of our
mailboxes now, right? ;)
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 01:59 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0