3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function url_parse($url){ $sflfdfldf=$url; if(strpos($url,"?")>-1){ $a=explode("?",$url,2); $url=$a[0]; $query=$a[1]; } if(strpos($url,"://")>-1){ $scheme=substr($url,0,strpos($url,"//")-1); $url=substr($url,strpos($url,"//")+2,strlen($url)); } if(strpos($url,"/")>-1){ $a=explode("/",$url,2); $url=$a[0]; $path="/".$a[1]; } if(strpos($url,":")>-1){ $a=explode(":",$url,2); $url=$a[0]; $port=$a[1]; } $host=$url; $url=null; foreach(array("url","scheme","host","port","path","query") as $var){ if(!empty($$var)){ $return[$var]=$$var; } } //return array("url"=>$sflfdfldf,"scheme"=>$scheme,"host"=>$host,"port"=>$port,"path"=>$path,"query"=>$query,"a"=>$url); return $return; } ?> <?php /* Compare two outputs */ //mine print_r(url_parse("http://login.yahoo.com?.src=ym&.intl=gb&.lang=zh-Hans-HK&.done=https://mail.yahoo.com")); //internal print_r(parse_url("http://login.yahoo.com?.src=ym&.intl=gb&.lang=zh-Hans-HK&.done=https://mail.yahoo.com"));
Output for 5.6.28, 7.0.20 - 7.2.0
Array ( [scheme] => http [host] => login.yahoo.com [query] => .src=ym&.intl=gb&.lang=zh-Hans-HK&.done=https://mail.yahoo.com ) Array ( [scheme] => http [host] => login.yahoo.com [query] => .src=ym&.intl=gb&.lang=zh-Hans-HK&.done=https://mail.yahoo.com )
Output for 4.3.4 - 5.6.21, 7.0.0 - 7.0.6
Array ( [scheme] => http [host] => login.yahoo.com [query] => .src=ym&.intl=gb&.lang=zh-Hans-HK&.done=https://mail.yahoo.com ) Array ( [scheme] => http [host] => login.yahoo.com?.src=ym&.intl=gb&.lang=zh-Hans-HK&.done=https [path] => //mail.yahoo.com )
Output for 4.3.2 - 4.3.3
Array ( [scheme] => http [host] => login.yahoo.com [query] => .src=ym&.intl=gb&.lang=zh-Hans-HK&.done=https://mail.yahoo.com ) Warning: parse_url(http://login.yahoo.com?.src=ym&.intl=gb&.lang=zh-Hans-HK&.done=https://mail.yahoo.com): Unable to parse url in /in/qMomP on line 41
Output for 4.3.0 - 4.3.1
Array ( [scheme] => http [host] => login.yahoo.com [query] => .src=ym&.intl=gb&.lang=zh-Hans-HK&.done=https://mail.yahoo.com ) Warning: parse_url(http://login.yahoo.com?.src=ym&.intl=gb&.lang=zh-Hans-HK&.done=https://mail.yahoo.com) [http://www.php.net/function.parse-url]: Unable to parse url in /in/qMomP on line 41