[SOLVED] preg_replace, including a function...
Posted: Fri Aug 22, 2003 4:20 pm
I have an issue that I just cant work out. I tried different ways, but I keep getting stuck.
A part of the script parses text to replace emails, with email-links. That works. But I would like to embed a email-harvester-blocker by decoding the emails, using a function. If the user clicks an email, he/shes is sendt to email.php that decodes the mail and so on...
I have these in the script...
...among other stuff. It works good, but I'm trying to add a email-harvester-blocker, by using the function mailencode($mail). So...
Ideas welcome.
A part of the script parses text to replace emails, with email-links. That works. But I would like to embed a email-harvester-blocker by decoding the emails, using a function. If the user clicks an email, he/shes is sendt to email.php that decodes the mail and so on...
I have these in the script...
Code: Select all
<?php
$patterns[] = "#\[email\](.*?)\[/email\]#si";
$replacements[] = '<a href="mailto:\1">\1</a>';
$patterns[] = "#\[email=(.*?){1}(.*?)\](.*?)\[/email\]#si";
$replacements[] = '<a href="mailto:\1\2">\3</a>';
$message = preg_replace($patterns, $replacements, $message);
?>Code: Select all
<?php
// something like this, tho the below obviously wont work...
$patterns[] = "#\[email=(.*?){1}(.*?)\](.*?)\[/email\]#si";
$replacements[] = '<a href="email.php?mail='.mailencode(\\1\\2).'">\3</a>';
//^--- edited the \1\2 doesn't show right in this snippet for some reason...
?>