Hey,
Ok using the following to convert text links (chris@chris.com) into HTML links for a newsletter.
// Turn emails into links
$Email = '(.*)\@(.*)\.(.*)';
$Expr = '/' . $Email . '/i';
$EmaiLink = preg_replace( $Expr, "<a href=\"mailto:\\1@\\2.\\3\">\\1@\\2.\\3</a>", $text );
Now that works fine, but when I then do this:
$text_formatted = nl2br($EmaiLink);
$text_formatted = stripslashes($text_formatted);
I get a "<br />" in my link....however, I don't get it when I use the following code to convert URL's into links:
// Match things beginning with [url]http://[/url] (or other protocols)
$NotAnchor = '(?<!"|href=|href\s=\s|href=\s|href\s=)';
$Protocol = '(http|ftp|https):\/\/';
$Domain = '[\w]+(.[\w]+)';
$Subdir = '([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?';
$Expr = '/' . $NotAnchor . $Protocol . $Domain . $Subdir . '/i';
$URLLink= preg_replace( $Expr, "<a href=\"$0\" title=\"$0\" target=\"_blank\">$0</a>", $text);
So if do this:
$text_formatted = nl2br($URLLink);
$text_formatted = stripslashes($text_formatted);
I don't get any "<br />" after my URL links - any ideas?
Cheers,
Chris