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" <[email protected]> sometimes it's "[email protected]" <[email protected]>. sometimes it's just the email address itself "[email protected]", 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 [email protected] $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" <[email protected]>, "[email protected]" <[email protected]>, "[email protected]" <[email protected]> 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" <[email protected]>, "[email protected]" <[email protected]>, "[email protected]" <[email protected]>'; $emails = getEmails($textInput); print_r($emails); //OUTPUT: //Array //( // [0] => [email protected] // [1] => [email protected] // [3] => [email protected] //) ?> 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
Archived
This topic is now archived and is closed to further replies.