This function will check the the given url has prefixed http or https. if it is not it will prefix httpon the given url.
function prefixHttpOnUrl($url= '', $prefix=''){
if ($url == '' OR $prefix=''){
return '';
}
if (substr($url, 0, 7) != 'http://' && substr($url, 0, 8) != 'https://'){
if($prefix =="http://"){
$url = 'http://'.$url;
}
else if($prefix =="https://"){
$url = 'http://'.$url;
}
else {
return '';
}
}
return $url;
}
prefixHttpOnUrl("www.phpqa.blogspot.com","http://") will return http://www.phpqa.blogspot.com
prefixHttpOnUrl("phpqa.blogspot.com","https://") will return https://phpqa.blogspot.com
prefixHttpOnUrl("http://phpqa.blogspot.com","http://") will return http://phpqa.blogspot.com
prefixHttpOnUrl("http://phpqa.blogspot.com","https://") will return http://phpqa.blogspot.com
enjoy PHP'ing
[Thursday, April 23, 2009
|
0
comments
]
Popular Posts
- Jquery based dynamic adding and removal of html elements.
- Creating Google map and adding markers ans polyline on it
- php question
- Questoin regarding classes
- Contact Me
- creating dynamic elements in HTML using Javascript.
- functiion for MD5 encrypting and decrypting
- Php Questions
- PHP Question and answers
- function to calculate difference between two dates
0 comments
Post a Comment
Please put your comments here. your questions, your suggestions, also what went wrong with me.