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 ? ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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? |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
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? ;) |