Jump to content

[SOLVED] preg_replace and modifier e


IceBear

Recommended Posts

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

<?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....

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.