Jump to content

[SOLVED] get email id from bunch of data


srinivas6203

Recommended Posts

Hi all

 

I have some bunch of data like this.

 

askdhasdkf[sld[askfsdjflasjdajjdljkd;askd;ad[addjljdlaldajdjad "[email protected]" sajdkasjdlsjd dsakdhal sjdlasjdksajdjsapj kdpsoakdpoa skdklasdsa daddasd dadsadj asjdoijdo; iqwueiqe pqjlnd sandsahdsj dghkjshd kadsadsakhdkjsahdkjd.

 

In the above paragraph there is a email id "[email protected]". I want to get that email id. I am not using database.

 

Is there any possibility to get that email id from that paragraph using php.

 

Kindly tell me ASAP. Its urgent.

 

Thanq

Link to comment
https://forums.phpfreaks.com/topic/117121-solved-get-email-id-from-bunch-of-data/
Share on other sites

Not sure what you mean compare. If you paragraph is contained in the variable $string then run it through the preg match function as per the code example.

Working code:

 

$string = "askdhasdkf[sld[askfsdjflasjdajjdljkd;askd;ad[addjljdlaldajdjad \"[email protected]\" sajdkasjdlsjd dsakdhal sjdlasjdksajdjsapj kdpsoakdpoa skdklasdsa daddasd dadsadj asjdoijdo; iqwueiqe pqjlnd sandsahdsj dghkjshd kadsadsakhdkjsahdkjd.";
if(preg_match('/\\b([a-zA-Z0-9._%-]+@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,4})\\b/', $string, $matches)) {
	print "I have found the email address: ".$matches[0];
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.