时间:2021-07-01 10:21:17 帮助过:15人阅读
echo gethostbyname("www.jbxue.com");
//则会输出www.jbxue.com //全局数组 echo $_SERVER[“HTTP_HOST”];
$url ="http://www.jbxue.com/index.php?referer=kakata.com"; $arr=parse_url($url); echo " "; print_r($arr); echo " “;
$url ="http://www.jbxue.com/index.php?referer=jbxue.com"; get_host($url); function get_host($url){ //首先替换掉http:// $url=str_replace("http://","",$url); //获得去掉http://url的/最先出现的位置 $position=strpos($url,"/"); //如果没有斜杠则表明url里面没有参数,直接返回url, //否则截取字符串 if($position==false){ echo $url; }else{ echo substr($url,0,$position); } } ?>
header("Content-type:text/html;charset=utf-8"); $url ="http://www.jbxue.com/index.php?referer=jbxue.com"; $pattern="/(http:\/\/)?(.*)\//"; if(preg_match($pattern,$url,$arr)){ echo "匹配成功"; echo "匹配到了".$arr[2]; } ?>