<?php
$url = "http://www.google.com";
echo preg_match("/^http(s?):\/\/(\w+\.)?\w+\-?\.\w{2,6}(.*)?$/", $url) ? "<a href = '$url'>$url</a>" : $url;