11-08-2009, 08:40 AM
Credits and Source: http://www.roscripts.com/
Name: Format Web Address
Description: This function formats a web address for use in a link.
Snippet:
Thankyou for reading. Be happy always
Name: Format Web Address
Description: This function formats a web address for use in a link.
Snippet:
PHP Code:
function formatWebAddress($webAddress) {
$originalWebAddress = $webAddress;
$webAddress = "*" . $webAddress;
$formattedWebAddress = "";
if (stripos($webAddress, "http://") == 1) { //starts with http://
if (substr_count($webAddress, ".") == 1) { //one dot only
$formattedWebAddress = $originalWebAddress;
$formattedWebAddress = insertString($formattedWebAddress, "www.", 7);
}
else
$formattedWebAddress = $originalWebAddress;
}
else { //does not start with http://
if (substr_count($webAddress, ".") == 1) //one dot only
$formattedWebAddress = "http://www." . $originalWebAddress;
elseif (substr_count($webAddress, ".") >= 2) //two dots only
$formattedWebAddress = "http://" . $originalWebAddress;
else
$formattedWebAddress = $originalWebAddress;
}
// add slash at end
if (substr_count($formattedWebAddress, "/") == 2) //if it has "//" at beginning
$formattedWebAddress .= "/";
$formattedWebAddress = strtolower($formattedWebAddress);
return $formattedWebAddress;
}
Thankyou for reading. Be happy always