For instance, I need to add http:// to submitted url like :
//www.mydomain.com/images/icon-32.png (double slash at the beginning)
or
www.mydomain.com/images/icon-32.png
Any idea?
For instance, I need to add http:// to submitted url like :
//www.mydomain.com/images/icon-32.png (double slash at the beginning)
or
www.mydomain.com/images/icon-32.png
Any idea?
This seems to work fine for your problem.
$url = "//mydomain.com/images/icon-32.png";
// or $url = "mydomain.com/images/icon-32.png";
// Checking if string starts with '//'
if(strpos($url, "//")===0){
$url = "http:" . $url;
}else{
// Checking if string doesn't already start with 'http://'
if(!strpos($url, "http://")===0 || strpos($url, "http://")===false)
$url = "http://" . $url;
}
echo $url;