HTML
|
|
|
|
<?php function autoLink($str) {
// link all urls and email
$str2 = preg_replace("/(?<!<a href=")(?<!")(?<!">)((http|https|ftp)://[w?=&./-]+)/","<a href="\1">\1</a>",$str);
$str2 = preg_replace("/((?<!<a href="mailto:)(?<!">)(?<=(>|s))[w_-]+@[w_.-]+[w]+)/","<a href="mailto:\1">\1</a>",$str2); return $str2;
} ?>
|
|
|
Usage Example
|
$str = "Testing regular URL <b>http://www.yahoo.com/test/test.html?sss=aa&aa=dd</b>.<br> Testing email <b>test@test.test.com</b><br> Testing email A tag <font size=+1><a href="mailto:sss@sss.eee.com">woo@woo.com</a><br>Now I am testing HTML A tag <a href="http://www.aaa.com/sss/aee.html" target="_base"><font color="red">http://www.asss.com/aa/aaa</font></a></font>";
echo autoLink($str);
|
|
|
Rate This Script
|
|
|
|