473,385 Members | 1,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

PHP and email addresses

The expression:

preg_match_all("/text.*?([A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6})/i",$f,
$matches);

Returns ONE email address on a line in $f beginning 'text' - how do I
retrieve ALL the email addresses on a line in $f beginning 'text' in php?

Many thanks

Nick
Jun 11 '06 #1
4 1395
Rik
Nick Bell wrote:
The expression:

preg_match_all("/text.*?([A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6})/i",$f,
$matches);

Returns ONE email address on a line in $f beginning 'text' - how do I
retrieve ALL the email addresses on a line in $f beginning 'text' in
php?

Many thanks


Without looking further at e-mail validation, adjust:
"/text.*?([A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6})/i"
to:
"/^text(:?.*?([A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}))*/i"

Note that your regex will think .@..xx a valid email-adress.

Grtz,
--
Rik Wasmus
Jun 11 '06 #2
Rik wrote:
Nick Bell wrote:
The expression:

preg_match_all("/text.*?([A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6})/i",$f,
$matches);

Returns ONE email address on a line in $f beginning 'text' - how do I
retrieve ALL the email addresses on a line in $f beginning 'text' in
php?

Many thanks


Without looking further at e-mail validation, adjust:
"/text.*?([A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6})/i"
to:
"/^text(:?.*?([A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}))*/i"

Note that your regex will think .@..xx a valid email-adress.

Grtz,

Thanks. The $f is the result of file_get_contents(...) and the
'beginning of line' function ^ doesn't seem to detect the beginnings of
lines generated using this method.

Any thoughts?

Nick
Jun 11 '06 #3
Rik
Nick Bell wrote:
Rik wrote:
Nick Bell wrote:
The expression:

preg_match_all("/text.*?([A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6})/i",$f,
$matches);

Returns ONE email address on a line in $f beginning 'text' - how do
I retrieve ALL the email addresses on a line in $f beginning 'text'
in php?

Many thanks


Without looking further at e-mail validation, adjust:
"/text.*?([A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6})/i"
to:
"/^text(:?.*?([A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}))*/i"

Note that your regex will think .@..xx a valid email-adress.

Grtz,

Thanks. The $f is the result of file_get_contents(...) and the
'beginning of line' function ^ doesn't seem to detect the beginnings
of lines generated using this method.


First: ^isn't a function.
Second: then try without:
"/text(:?.*?([A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}))*/i"

Grtz,
--
Rik Wasmus
Jun 12 '06 #4
Nick Bell <me@privacy.net> wrote:
The expression:

preg_match_all("/text.*?([A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6})/i",$f,
$matches);

Returns ONE email address on a line in $f beginning 'text' - how do I
retrieve ALL the email addresses on a line in $f beginning 'text' in php?


This isn't foolproof by a long shot. Every printable character except [,
\, and ] is valid in an RFC2822 e-mail address, and even [ and ] can be
used if the address is wrapped in quotes.

The full regular expression required to match an RFC2822 compliant e-mail
address is more than 6,000 characters long, and is one of the gems in
Friedl's book "Mastering Regular Expressions".

It is common to use "*" in an e-mail address, for example. Sendmail has a
feature that uses it. If you send to "ab*****@joe.com", it will try find
an alias for "abc*def" exactly. Failing that, it will send the message to
"ab*@joe.com". This is great for spam catching; I can sign up with web
sites as "ti******@probo.com" without defining it, and if I get to much
spam, I just add a specific alias for that which routes to null.
--
- Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Jun 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Jim | last post by:
I have contact info including email address in MySQL. If I use php to extract them into online directory, can a spambot harvest the address? or does the spambot read the raw php code? I...
10
by: dave | last post by:
Hello, I'm creating a site that has several contact email addresses. These are vlid addresses, i'm wondering if i can use php to alter these addresses so that spam harvesters can't get them, yet a...
2
by: Hoang | last post by:
anyone know of an algorithm to filter out real email addresses as opposed to computer generated email addresses? I have been going through past email archives in order to find friends email...
5
by: Paul Cheevers | last post by:
Hi, This is driving me nuts to say the least!!!!! I am trying to send an email from some server side ASP code and the CC field is giving me some problems. The code works fine if I have one...
8
by: JayB | last post by:
We sent out an email today to a list of subscribers from our database using ASP and CDO. For some reason, many people received it twice, including myself. I checked the database and there were do...
117
by: Steevo | last post by:
Any suggestions as to the best programs for cloaking email addresses? Many thanks -- Steevo
1
by: divya | last post by:
I have a form which has a textarea,name - txtTo where he adds email addresses.Now when he clicks on sendemail I want to open a mailto link with addresses taken from textarea. Example I added...
8
by: needhelp | last post by:
Hi there, I really need some help, everything I've tried, all I've found, doesn't seem to work. I have lost an email address which is very important to me. I really need to contact that person...
4
by: chris | last post by:
I need to maintain a list of subscribers to an email list for a "newsletter" that will be sent via a web form probably once a month. I anticipate low numbers--tens to maybe one hundred subscribers...
45
by: Dennis | last post by:
Hi, I have a text file that contents a list of email addresses like this: "foo@yahoo.com" "tom@hotmail.com" "jerry@gmail.com" "tommy@apple.com" I like to
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.