[email protected] 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 https://forums.phpfreaks.com/topic/182109-script-to-catch-email-addresses-in-paragraph/ 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 https://forums.phpfreaks.com/topic/182109-script-to-catch-email-addresses-in-paragraph/#findComment-960707 Share on other sites More sharing options...
[email protected] 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 [email protected] ---------- Forwarded message ---------- From //in these type of strings I think need to use regex... any help Quote Link to comment https://forums.phpfreaks.com/topic/182109-script-to-catch-email-addresses-in-paragraph/#findComment-960732 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 https://forums.phpfreaks.com/topic/182109-script-to-catch-email-addresses-in-paragraph/#findComment-960782 Share on other sites More sharing options...
[email protected] Posted November 19, 2009 Author Share Posted November 19, 2009 simple emails to be entered in db table [email protected] [email protected] [email protected] ... Quote Link to comment https://forums.phpfreaks.com/topic/182109-script-to-catch-email-addresses-in-paragraph/#findComment-960792 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 https://forums.phpfreaks.com/topic/182109-script-to-catch-email-addresses-in-paragraph/#findComment-960800 Share on other sites More sharing options...
[email protected] 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 [email protected] ---- Forwarded Message ---- From: Sattar <[email protected]> To: [email protected] Sent: Tue, November 17, 2009 9:23:57 AM My output is like [email protected] ----- // notice '-----' at the end, I need to omit that. [email protected] [email protected] 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 https://forums.phpfreaks.com/topic/182109-script-to-catch-email-addresses-in-paragraph/#findComment-961558 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 https://forums.phpfreaks.com/topic/182109-script-to-catch-email-addresses-in-paragraph/#findComment-961620 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 https://forums.phpfreaks.com/topic/182109-script-to-catch-email-addresses-in-paragraph/#findComment-961801 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 https://forums.phpfreaks.com/topic/182109-script-to-catch-email-addresses-in-paragraph/#findComment-961861 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 https://forums.phpfreaks.com/topic/182109-script-to-catch-email-addresses-in-paragraph/#findComment-964365 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.