View Single Post
  #2 (permalink)  
Old November 4th, 2003, 11:37 PM
richard.york's Avatar
richard.york richard.york is offline
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

I was able to figure out a way to get Nik's example working.

Apparently my decode function which decodes the message body from quoted-printable was creating a conflict, so I moved that to happen before I attempted regular expression replacement.

I used create_function() to use preg_replace_callback from within my class.

$msg_body = imap_fetchbody($this->mailbox, $mid, $pid);
$msg_body = $this->decode_message($msg_body, $this->encoding[$mid][$i]);

$pattern = '!\bhttps?://([\w\-]+\.)+[a-zA-Z]{2,3}(/(\S+)?)?\b!';

$msg_body = htmlspecialchars($msg_body);
$msg_body = preg_replace_callback($pattern, create_function('$matches', 'return "<a href=\'".$matches[0]."\' target=\'_new\'>".$matches[0]."</a>";'), $msg_body);

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
Reply With Quote