I got this code to find text in a string that looks like links and transform them into an a-tag link. Since I also use tiny mce to input the data this situation often occurs (since tiny mce and other editor loves paragraphs).
string
http://www.google.se</ p>
and the script produces the link
href=" http://www.google.se</ p>"
(..hmm just discoverd stackoverflows text to link script works :))
code
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/";
if(preg_match($reg_exUrl, $string, $url)) {
return preg_replace($reg_exUrl, "<a href=\"" . $url[0] . "\" target=\"_blank\">" . $url[0] . "</a> ", $string);
}
how can I change the preg to stop the link when an < is found?
plus maybe tips on better text to link scripts. actually where does stackoverflows texteditor come from?
Thanks!
Try this one. Replaced \S with [^\s<]