Solved

Email parser from HTML

Posted on 2011-02-12
1
230 Views
Last Modified: 2012-05-11
Can you help me with a code to extract email addresses from a HTML? The html will be pasted in the text area <textarea> . On submit it should give me email addresses separated one line after the other from the code.
0
Comment
Question by:nainil
1 Comment
 
LVL 34

Accepted Solution

by:
Beverley Portlock earned 250 total points
ID: 34880267
OK, Asumming that your addresses are separted by white space, I have simulated the input from the textarea in $test

<?php

$test = '
abc@example.com
de-fg@example.co.uk
shs.sksk@example.org
';

$pattern = '|\s?([-\.0-9a-z]{2,}@[-0-9a-z\.]{3,})\s?|';

preg_match_all( $pattern, $test, $matches );

print_r( $matches [1]);

Open in new window


Produces

Array
(
    [0] => abc@example.com
    [1] => de-fg@example.co.uk
    [2] => shs.sksk@example.org
)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now