srinivas6203 Posted July 29, 2008 Share Posted July 29, 2008 Hi all I have some bunch of data like this. askdhasdkf[sld[askfsdjflasjdajjdljkd;askd;ad[addjljdlaldajdjad "jshdkjshdsd@gmail.com" sajdkasjdlsjd dsakdhal sjdlasjdksajdjsapj kdpsoakdpoa skdklasdsa daddasd dadsadj asjdoijdo; iqwueiqe pqjlnd sandsahdsj dghkjshd kadsadsakhdkjsahdkjd. In the above paragraph there is a email id "jshdkjshdsd@gmail.com". 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 Quote Link to comment https://forums.phpfreaks.com/topic/117121-solved-get-email-id-from-bunch-of-data/ Share on other sites More sharing options...
ignace Posted July 29, 2008 Share Posted July 29, 2008 yeah i think its possible but you will need to use regex to achieve it http://be.php.net/manual/en/book.regex.php Quote Link to comment https://forums.phpfreaks.com/topic/117121-solved-get-email-id-from-bunch-of-data/#findComment-602428 Share on other sites More sharing options...
JonnoTheDev Posted July 29, 2008 Share Posted July 29, 2008 // $string is your sentence containing an email address preg_match('/\\b([a-zA-Z0-9._%-]+@(?:[a-zA-Z0-9-]+\\.)+[a-zA-Z]{2,4})\\b/', $string, $matches); print_r($matches); Quote Link to comment https://forums.phpfreaks.com/topic/117121-solved-get-email-id-from-bunch-of-data/#findComment-602431 Share on other sites More sharing options...
srinivas6203 Posted July 29, 2008 Author Share Posted July 29, 2008 hi neil.johnson How can i compare this and how can i get email. can u tell me the code. Quote Link to comment https://forums.phpfreaks.com/topic/117121-solved-get-email-id-from-bunch-of-data/#findComment-602448 Share on other sites More sharing options...
JonnoTheDev Posted July 29, 2008 Share Posted July 29, 2008 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 \"jshdkjshdsd@gmail.com\" 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]; } Quote Link to comment https://forums.phpfreaks.com/topic/117121-solved-get-email-id-from-bunch-of-data/#findComment-602450 Share on other sites More sharing options...
srinivas6203 Posted July 29, 2008 Author Share Posted July 29, 2008 Thanx neil.johnson . its working. Thanq to ignace Quote Link to comment https://forums.phpfreaks.com/topic/117121-solved-get-email-id-from-bunch-of-data/#findComment-602466 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.