Xtnct00WS6 Posted February 26, 2008 Share Posted February 26, 2008 I have a text box and I'm trying to get the number of actual email addresses that are in it. Problem is the format. Sometimes the input box has: "john smith" <jonnyboy@gmail.com> sometimes it's "jonnyboy@gmail.com" <jonnyboy@gmail.com>. sometimes it's just the email address itself "jonnyboy@gmail.com", I have a function to strip out the < > and " " but how do I strip it out of each one? Here's the code: echo $firstpart; // shows Heidi Klum Supermodel echo "<br>"; echo $secondpart; // shows info@HeidiKlum.com $firstpart = extractBetweenDelimeters($Recipients,"\"","\""); $secondpart = extractBetweenDelimeters($Recipients,"<",">"); function extractBetweenDelimeters($inputstr,$delimeterLeft,$delimeterRight) { $posLeft = stripos($inputstr,$delimeterLeft)+1; //posLeft is returning a number for the character that's the left of < $posRight = stripos($inputstr,$delimeterRight,$posLeft+1); $each = substr($inputstr,$posLeft,$posRight-$posLeft); return $each; } A likely string of emails would be: "Bobeee Bob" <Bob@gmail.com>, "Ron@hotmail.com" <Ron@hotmail.com>, "johnee@ruckus.com" <johnee@ruckus.com> Quote Link to comment https://forums.phpfreaks.com/topic/93186-count-each-email-in-a-text-boxinput-field/ Share on other sites More sharing options...
Psycho Posted February 26, 2008 Share Posted February 26, 2008 this will get all the email addresses in the input string and remove duplicates: <?php function getEmails($intputStr) { preg_match_all('/[\w\+-]+([\.]?[\w\+-])*@[a-zA-Z0-9]{2,}([\.-][a-zA-Z0-9]{2,})*\.[a-zA-Z]{2,4}/', $intputStr, $matches); $emailListAry = array_unique ($matches[0]); return $emailListAry; } $textInput = '"Bobeee Bob" <Bob@gmail.com>, "Ron@hotmail.com" <Ron@hotmail.com>, "johnee@ruckus.com" <johnee@ruckus.com>'; $emails = getEmails($textInput); print_r($emails); //OUTPUT: //Array //( // [0] => Bob@gmail.com // [1] => Ron@hotmail.com // [3] => johnee@ruckus.com //) ?> Quote Link to comment https://forums.phpfreaks.com/topic/93186-count-each-email-in-a-text-boxinput-field/#findComment-477457 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.