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][email protected][/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 Link to comment https://forums.phpfreaks.com/topic/60432-solved-preg_replace-and-modifier-e/ 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][email protected][/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.... Link to comment https://forums.phpfreaks.com/topic/60432-solved-preg_replace-and-modifier-e/#findComment-300622 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! Link to comment https://forums.phpfreaks.com/topic/60432-solved-preg_replace-and-modifier-e/#findComment-300625 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.