Sunday, January 20, 2013

CONVERTING WWW ENTERED TEXT TO ACTUAL LINKS

 
HOW TO CONVERT NORMAL TEXT WEB LINKS INTO ACTUAL LINKS FOR BLOGS AND WALL POST.
This code will remove any www.something .somethings from all text and convert them to actual links.

$string = " bla bla bla http://www.example.com/ bla bla http://www.example.net/ bla bla bla";

$m = preg_match_all('/www.\/\/[a-z0-9A-Z.]+(?(?=[\/])(.*))/', $string, $match);

if ($m) {
$links=$match[0];
for ($j=0;$j<$m;$j++) {
$string=str_replace($links[$j],''.$links[$j].'">'.$links[$j].'</a>',$string);
}
}

echo $string;

?>