salman_ahad@yahoo.com Posted November 19, 2009 Share Posted November 19, 2009 I have a pragraph full of email addresses. I need to catch emails only and ignore the rest. if ($_POST['Submit']) { $para = $_POST['para']; $emails = split('[<>;:,\/"{}*!?]',$para); foreach ($emails as $email) { if (empty($email)) { continue;} //I need help here for deleting those empty rows. else { // echo $email.'<br \>'; // or insert in database..... ............ } } } Also I need help applying this email validation ereg, guide me here too please $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$"; //or '/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/' //or Anything better before inserting in database?? Quote Link to comment Share on other sites More sharing options...
emopoops Posted November 19, 2009 Share Posted November 19, 2009 shouldnt this be in the regex forum? Quote Link to comment Share on other sites More sharing options...
salman_ahad@yahoo.com Posted November 19, 2009 Author Share Posted November 19, 2009 Yes I think it should be in regex, but I dont know how ?? My updated code if ($_POST['Submit']) { $para = $_POST['para']; $emails = split('[<>;:,\/"{}*!?]',$para); foreach ($emails as $email) { if (empty($email)) { continue;} if(stristr($email, '@') === FALSE) { //Checking for those strings containing '@' continue;} else { echo $email.'<br \>'; } } } My output is almost there...but I am also getting strings like name@yahoo.co.in ---------- Forwarded message ---------- From //in these type of strings I think need to use regex... any help Quote Link to comment Share on other sites More sharing options...
emopoops Posted November 19, 2009 Share Posted November 19, 2009 what format are u trying to get those multpile emails in?> Quote Link to comment Share on other sites More sharing options...
salman_ahad@yahoo.com Posted November 19, 2009 Author Share Posted November 19, 2009 simple emails to be entered in db table user1@site.com user2@site2.co.in user3@xx.nz ... Quote Link to comment Share on other sites More sharing options...
emopoops Posted November 19, 2009 Share Posted November 19, 2009 im sorry are they getting entered all in one feild sepearted by a break? or is it one email per feild or row or what? Quote Link to comment Share on other sites More sharing options...
salman_ahad@yahoo.com Posted November 20, 2009 Author Share Posted November 20, 2009 Now this is my updated code to take junk of data and catch only email addresses. <?php if ($_POST['Submit']) { $para = $_POST['para']; $emails = preg_split( '@[ <>;:,\\\\/"{}*!?]@', $para ); //split the para when there are signs encountered, excluding '@', '.', '_' foreach ($emails as $email) { if (empty($email)) { continue;} if(stristr($email, '@') === FALSE) { continue;} else { echo $email.'<br \>'; continue; } } } //$regexp = '/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/'; ?> Now this is my input data abwbasit2002@yahoo.com ---- Forwarded Message ---- From: Sattar <sattardiq@gmail.com> To: wajihah7@yahoo.com Sent: Tue, November 17, 2009 9:23:57 AM My output is like abwbasit2002@yahoo.com ----- // notice '-----' at the end, I need to omit that. sattardiq@gmail.com wajihah7@yahoo.com Sent //notice 'Sent' at the end, I need to omit that. //Dont know how to modify my code more to remove those Quote Link to comment Share on other sites More sharing options...
emopoops Posted November 20, 2009 Share Posted November 20, 2009 i dont understand a thing ur doing with it, most likely most dont. maybe u could explain what u are trying to do? Quote Link to comment Share on other sites More sharing options...
salathe Posted November 20, 2009 Share Posted November 20, 2009 Why not just call preg_match_all() with a pattern that looks for something-that-looks-like-an-email ? I think your approach above is trying too hard to be complicated. Quote Link to comment Share on other sites More sharing options...
thebadbad Posted November 20, 2009 Share Posted November 20, 2009 Yeah, like salathe says, something simple like <?php preg_match_all('~\b[^@\s<>]+@[^@\s<>]+~', $_POST['para'], $matches); echo '<pre>' . print_r($matches[0], true) . '</pre>'; ?> should do the job fine, if you don't care about validating the emails. Quote Link to comment Share on other sites More sharing options...
emopoops Posted November 23, 2009 Share Posted November 23, 2009 u need to make sure u split the emails up by a space. because theres no spaces in emails. Quote Link to comment 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.