Add http:// if it's not exists in the URL http://stackoverflow.com/questions/2762061/how-to-add-http-if-its-not-exists-in-the-url
<?php
$url = 'www.google.com';
$init = microtime(true);
for( $i = 1; $i < 1000000; $i++ ) {
addhttp($url);
}
echo microtime(true) - $init;
echo "<hr />";
$init = microtime(true);
for( $i = 1; $i < 1000000; $i++ ) {
addhttp( $url );
}
echo microtime(true) - $init;
function addhttp($url) {
if (!preg_match("~^(?:f|ht)tps?://~i", $url)) {
$url = "http://" . $url;
}
return $url;
}
function addScheme($url, $scheme = 'http://'){
return parse_url($url, PHP_URL_SCHEME) === null ?
$scheme . $url : $url;
}
?>