views:

41

answers:

5

Hello guys,

I want to fetch all the email address in a paragraph. could you please help me

Thanks a lot

A: 

Try this: regEx: /[-.\w]+@[-.\w]+/i

Jet
This is WAY too generic, and will catch things like "call me@work", which is not an email address at all.
Ryan Gooler
A: 

You can use the preg_match_all function. The syntax would be like this:

//Filter our the email addresses and store it in $emails
preg_match($regexp,$text,$emails);

//Print out the array of emails
print_r($emails);

where:

  • $regexp is a regular expression for an email
  • $text is the paragraph of text
  • $emails is the output array of email addresses

A regular expression can vary depending on how loose or tight you want it to be. Try crafting your own, so that it follows your standards, but if you're having trouble, you can just Google Email Regular Expressions.

P.S. I hope you're not planning to use this to spam somehow.

Kranu
A: 

As suggested by others, please put more for of an effort into your questions.

The following is a very basic implementation of what you're after. It does ignore some email types, but hey, its the same amount of effort you put in.

  $matches = preg_match_all(
    "/[a-z0-9]+([_\\.-][a-z0-9]+)*@([a-z0-9]+([\.-][a-z0-9]+)*)+\\.[a-z]{2,}/i",
    $text,
    $emails
  );

$text is your paragraph. $emails is the array of matched values.

Russell Dias
+2  A: 

Look here for Email regexes:

http://www.regular-expressions.info/email.html

It even has the "The Official Standard: RFC 2822" supporting email regexes.

shamittomar
A: 
<?php
$paragraph="this is test [email protected] [email protected] testing";
$pattern="/([\s]*)([_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*([ ]+|)@([ ]+|)([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,}))([\s]*)/i"; preg_match_all($pattern, $paragraph, $matches);

print_r($matches[0]);
?>
JapanPro
Thanks buddy :)
john