nemesis_256
04-06-2007, 07:01 PM
I'm trying to make a regular expression that will look through a string of text which has multiple email addresses (all just plain text). What I want it to do is to add the html anchor tag around the addresses. Here's what I have up to now.
ereg('[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+', $comment, $regs);
$comment = ereg_replace($regs[0], "<a href=\"mailto:$regs[0]\">$regs[0]</a>", $comment);
The first email address works fine, but after that it doesn't. So obviously, ereg only goes through until it finds the first match. Is this what it's supposed to do? I mean the results are saved in an array...
If I run through that code again it will just find the first email address, which this time will end up being the one between the anchor tag. So how do I make this work?
ereg('[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+', $comment, $regs);
$comment = ereg_replace($regs[0], "<a href=\"mailto:$regs[0]\">$regs[0]</a>", $comment);
The first email address works fine, but after that it doesn't. So obviously, ereg only goes through until it finds the first match. Is this what it's supposed to do? I mean the results are saved in an array...
If I run through that code again it will just find the first email address, which this time will end up being the one between the anchor tag. So how do I make this work?