View Single Post
  #1 (permalink)  
Old November 4th, 2003, 09:27 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 perl compatible regular expressions

I was wondering if anyone knew of a good tutorial on perl compatible regular expressions. I am trying to write a regular expression that would replace links in an email program with HTML formatted links.

I tried Nik's example in the following thread:

But have seem to run into a snag, in that I designed my program as a class and cannot seem to find a way to do the callback function from the class. I also tried defining the callback function in global scope, but the regular expression function didn't return the mail body. I've actually attempted several examples that I found on the web and none of them bring back the message body.

Here is one example that I tried:
$msg_body = imap_fetchbody($this->mailbox, $mid, $pid);

$msg_body = preg_replace("/([\w\.]+)(@)([\S\.]+)\b/i","<a href=\"mailto:$0\">$0</a>", $msg_body);
$msg_body = preg_replace("(^)"<a href=\"http$3://$4$5\"target=\"_blank\">$2$4$5</a>", $msg_body);

Neither of these look like a very good solution.

If I comment out the preg_replace functions the message body shows up, when I use them I get a blank message body.

I don't know much about regular expressions anyway, so I am at a loss to see where it might be going wrong. In all of my PHP books none of them seem to discuss perl compatible regular expressions in any detail, but they do talk quite a bit about POSIX-style regular expressions.

Thanks in advance!
: )

Smiling Souls
Reply With Quote