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]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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.