3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function chiii($url,$href){ if(strstr($href,"#")){ if(substr($href,0,1)=="#")return null; $p=explode('#',$href); $href=$p[0]; } if(substr($url,strlen($url)-1,strlen($url))=='/')$base=$url; else $base=dirname($url); if(substr($href,0,2)=="//"){ $p=parse_url($url); return $p['scheme'].$href; }else if(substr($href,0,1)=="/"){ $p=parse_url($url); return $p['scheme']."//".$p['host'].$href; }else if(preg_match('/^https*\:\/\//',$href))return $href; else if(substr($href,0,3)=="../"){ $pat="/^\.\.\//"; echo "back"; while(preg_match($pat,$href)){ $href=preg_replace($pat,'',$href); $base=dirname($base); } return $base."/".$href; }else if(preg_match("/[a-z]+\:/",$href))return null; else return $base.$href; return "NONE"; } $url="http://netor.ir/hello/wel/"; echo chiii($url,"../client#hello"); echo chiii($url,"client/256/"); ?>
based on YtWqS
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.0alpha1
backhttp://netor.ir/hello/clienthttp://netor.ir/hello/wel/client/256/