日期:2014-05-16 浏览次数:20592 次
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 "
“; <!--?php <br ?--> $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);
}
}
?><!--?php <br ?--> 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];
}
?>