IceBear Posted July 17, 2007 Share Posted July 17, 2007 Hi, I'm trying to figure out how to use preg_replace with modifier e and my current *working* code... however, I'm clueless not very familiar with the regex stuff... So here is what I have: $txt = "foobar, some more text, whatever... write something to [mail]my@email.com[/mail] okay?"; $txt = preg_replace("&\[MAIL\](.*?)\[/MAIL\]&i","<a href=\"mailto:$1\" target=\"_blank\">$1</a>",$txt); So, this works fine... What I want now, is just the same but with a function in the replace text and modifier e... But... As I said, I have no idea how to do that... It should look something like that: $txt = preg_replace("&\[MAIL\](.*?)\[/MAIL\]&i","<a href=\"mailto:".pmp("$1")."\" target=\"_blank\">".pmp("$1")."</a>",$txt); Thanks for your help! IceBear Quote Link to comment Share on other sites More sharing options...
Wildbug Posted July 17, 2007 Share Posted July 17, 2007 <?php $txt = "foobar, some more text, whatever... write something to [mail]my@email.com[/mail] okay?"; $txt = preg_replace("&\[MAIL\](.*?)\[/MAIL\]&ie",'\'<a href="mailto:\' . pmp(\'$1\') . \'" target="_blank">\' . pmp(\'$1\') . \'</a>\'', $txt); ?> The only thing to guard against is escaped double quotes. You may need to put a str_replace('\"', '"', $1) in either the replacement string or pmp() function. Of course, they shouldn't occur in an e-mail address, but just so you know.... Quote Link to comment Share on other sites More sharing options...
IceBear Posted July 17, 2007 Author Share Posted July 17, 2007 Thank you very much for your quick help! Quote Link to comment 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.