I have a function to create html links from text in php. I'd like to always add http:// before links.
function toLink($titulo){
$url = '~(?:(https?)://([^\s<]+)|(www\.[^\s<]+?\.[^\s<]+))(?<![\.,:])~i';
$titulo = preg_replace($url, '<a href="$0" target="_blank" title="$0">$0</a>', $titulo);
return $titulo;
}
and:
$titulo = toLink("some text: www.example.com");
I'd like this url to be convert to <a href="http://www.example.com">
instead of <a href="www.example.com">
.
In other words, I ALWAYS would like to have http on my links. If the text url has http or not. Any ideas how to always have http at the begining of the url?
thanks.