I’m using the following code just to convert any URL to starts with http:// or https://
but this function makes problem with exact type urls as example
$url = 'www.youtube.com/watch?v=_ss'; // url without http://
function convertUrl ($url){
$parts = parse_url($url);
$returl = "";
if (empty($parts['scheme'])){
$returl = "http://".$parts['path'];
} else if ($parts['scheme'] == 'https'){
$returl = "https://".$parts['host'].$parts['path'];
} else {
$returl = $url;
}
return $returl;
}
$url = convertUrl($url);
echo $url;
the output
http://www.youtube.com/watch
expected output as i want
http://www.youtube.com/watch?v=_ss
as i mainly use it just to fix any url without http:// so is there any way to edit this function so it can pass all urls with =_ as shown in the example ! as it really annoying me ~ thanks
You’ll want to get:
Because that’s the query section of the URL.
You can modify your function to do this: