我正在使用以下代码将任何 URL 转换为以http://
or开头,https://
但是此函数会导致精确类型 url 出现问题,例如
$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;
输出
http://www.youtube.com/watch
我想要的预期输出
http://www.youtube.com/watch?v=_ss
因为我主要使用它来修复任何 url,http://
所以有没有办法编辑这个函数,所以它可以传递所有 url,=_
如示例所示!因为它真的很烦我~谢谢