Check URL...How to add http:// and https:// and www in ur existing url if not present in url in php?
<?php
echo "<pre>";
$url = "ervijaysinhparmar.blogspot.com";//$_SERVER['HTTP_HOST'];
echo "User URL::<b>".$url."<b><br>";
//$pattern= "#^http://www\.|https://www\.[a-z0-9-_.]+\.[a-z]{2,4}$#i";
// [VERY] Quick email check:
if(stristr($url, "http://") ) {
//echo "Ok";
}
elseif(stristr($url, "https://") ) {
//echo "Ok";
}
else{
//echo "No";
$url = "http://".$url;
}
if (stristr($url, "www.") ) {
//echo "Ok";
}
else{
//echo "www. is not available";
$parse = parse_url($url);
$url = $parse['scheme']."://www.".$parse['host'];
}
echo "Final URL::<br><b>".$url."<b><br>";
exit;
?>
By Vijaysinh Parmar.
<?php
echo "<pre>";
$url = "ervijaysinhparmar.blogspot.com";//$_SERVER['HTTP_HOST'];
echo "User URL::<b>".$url."<b><br>";
//$pattern= "#^http://www\.|https://www\.[a-z0-9-_.]+\.[a-z]{2,4}$#i";
// [VERY] Quick email check:
if(stristr($url, "http://") ) {
//echo "Ok";
}
elseif(stristr($url, "https://") ) {
//echo "Ok";
}
else{
//echo "No";
$url = "http://".$url;
}
if (stristr($url, "www.") ) {
//echo "Ok";
}
else{
//echo "www. is not available";
$parse = parse_url($url);
$url = $parse['scheme']."://www.".$parse['host'];
}
echo "Final URL::<br><b>".$url."<b><br>";
exit;
?>
By Vijaysinh Parmar.
No comments:
Post a Comment