Posted by brendan on 09/14/05 13:27
"Chung Leong" <chernyshevsky@hotmail.com> wrote in message
news:1126644521.260826.103720@g44g2000cwa.googlegroups.com...
> That doesn't work, because the pattern will match again as soon as the
> regexp engine looks one letter to the right.
> A job like this is easier with preg_replace_callback(), arguably the
> most powerful text manipulation function in PHP. Example:
>
> function antispam($m) {
> return ($m[1]) ? $m[0] :
> "<script>document.write('<a
>
href=\'mailto:'+'{$m[3]}'+'@'+'{$m[4]}'+'\'>'+'$m[3]'+'@'+'$m[4]'+'</a>');</
script>";
> }
>
>
preg_replace_callback('/(mailto:)?\s*(([_\\.0-9a-z-]+)@([_\\.0-9a-z-]+))/i',
> 'antispam', $string);
>
Excellent, this works perfectly.
[Back to original message]
|