Jump to content


Photo

simple preg_match help


  • Please log in to reply
3 replies to this topic

#1 kevinkorb

kevinkorb
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationSt. Louis, MO

Posted 18 July 2006 - 05:25 PM

I am parsing all the email addresses out of a string in the format of:

name <email@address.com>, some other person <otherperson@otherdomain.com> ...... etc.

I want to make an array of all my email addresses which would just be <(anything between)>

If you could give me the whole preg_match call that would be great as I'm not used to regular expressions.  I'm on PHP5

Thanks.

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 18 July 2006 - 05:59 PM

<my@phpfreaks.com>

you can not have a string with the <less >more signs ok

try your self ok i bet that you can not echo those emails out ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 toplay

toplay
  • Staff Alumni
  • Advanced Member
  • 973 posts

Posted 18 July 2006 - 06:23 PM

redarrow, you can display that with htmlentities().

kevinkorb, here's an example:
<?php

$emails = 'name <email@address.com>, some other person <otherperson@otherdomain.com>';
$matches = array();
preg_match_all('/\b([A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4})\b/i', $emails, $matches, PREG_PATTERN_ORDER);
for ($i = 0, $cnt = count($matches[0]); $i < $cnt; $i++) {
	echo $matches[0][$i], "\n<br/>";
}


?>

Outputs:

email@address.com
otherperson@otherdomain.com



#4 kevinkorb

kevinkorb
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts
  • LocationSt. Louis, MO

Posted 18 July 2006 - 06:46 PM

Thank you very much... exactly what I needed.

-Kevin




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users