Hello guys,
I want to fetch all the email address in a paragraph. could you please help me
Thanks a lot
Hello guys,
I want to fetch all the email address in a paragraph. could you please help me
Thanks a lot
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:
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.
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.
Look here for Email regexes:
http://www.regular-expressions.info/email.html
It even has the "The Official Standard: RFC 2822" supporting email regexes.
<?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]);
?>