echo next(explode("=", $_SERVER["QUERY_STRING"]));echo $_GET[$id];一样的哦
$url = $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];echo $url; $filename= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];echo $filename;
如果字符串中只有域名:
1 2 3 $str = 'aaa.baidu.com' ; preg_match( "/[\w\-]+\.\w+$/" , $str , $arr ); echo $arr [0]; 用到
如果是完整的URL:
1 2 3 $str = 'fdsa.fdsa.baidu.com/fdsa/rewl.html' ; preg_match( "/[\w\-]+\.\w+(?=\/)/" , $str , $arr ); echo $arr [0]; 追问 请问如何提取降一级的域名呢如xxx.xxx.com就提取xxx.com而xxx.xxx.xxx.com就匹配xxx.xxx.com 回答 1 2 3 4 5 6 7 8 9 10 11 12 $str = 'http://we.aa.baidu.com/dfsa.html' ; $str2 = 'http://baike.baidu.com/' ; //正则 $reg = "#(?<=\\.)([\\w\-]+\\.)+?\\w+(?=/)#ix" ; //匹配第一组 preg_match( $reg , $str , $arr ); echo $arr [0]; echo '' ; //匹配第二组 preg_match( $reg , $str2 , $arr ); echo $arr [0];
嗯,使用正则的断言,很一句代码就实现了。
=================================================================================
=======================================================================================
ASP如何获取文件地址呢?直接看例子:
如果要想获取这样的地址:http://192.168.0.5/super/super_article.asp?id=4那么我们就只要获取:192.168.0.5---><%=Request.ServerVariables("HTTP_HOST")%>/super/super_article.asp-----><%=Request.ServerVariables("URL")%>id=4----><%=Request.ServerVariables("QUERY_STRING")%>那么我们把上面的地址合起来就可以完成任务了:http://192.168.0.5/super/super_article.asp?id=4----->;http://<;%=Request.ServerVariables("HTTP_HOST")&request.ServerVariables("URL")&"?"&Request.ServerVariables("QUERY_STRING") %>使用获取url中的文件名和传过来的值: 本文件ip路径:<%="http://" & request.servervariables("server_name")&request.servervariables("script_name") %> 就可以了.. 下面是具体其它一些获取服务器信息的一些方法 几个常用Request.ServerVariables的中文 本文件ip路径:<%="http://" & request.servervariables("server_name")&request.servervariables("script_name") %> 本机ip:<%=request.servervariables("remote_addr")%> 服务器名:<%=Request.ServerVariables("SERVER_NAME")%> 服务器IP:<%=Request.ServerVariables("LOCAL_ADDR")%> 服务器端口:<%=Request.ServerVariables("SERVER_PORT")%> 服务器时间:<%=now%> IIS版本:<%=Request.ServerVariables("SERVER_SOFTWARE")%> 脚本超时时间:<%=Server.ScriptTimeout%> 本文件路径:<%=server.mappath(Request.ServerVariables("SCRIPT_NAME"))%> 服务器CPU数量:<%=Request.ServerVariables("NUMBER_OF_PROCESSORS")%> 服务器解译引擎:<%=ScriptEngine & "/"& ScriptEngineMajorVersion&"."&ScriptEngineMinorVersion&"."& ScriptEngineBuildVersion %> 服务器操作系统:<%=Request.ServerVariables("OS")%> 支持的文件类型:<%=Request.ServerVariables("HTTP_Accept")%> 访问的文件路径:<%=Request.ServerVariables("HTTP_url")%> 用户代理的信息:<%=Request.ServerVariables("HTTP_USER_AGENT")%> 获取url中的文件名和传过来的值:request.ServerVariables("script_name")+"?"+request.ServerVariableS("QUERY_STRING")ASP如何获取文件所在目录在ASP中,我们都知道文件的路径怎么获取,但是文件所在目录却不知道怎么办?我们获取文件的路径是:<%=Request.ServerVariables("PATH_TRANSLATED")%>既然我们都获取了文件的路径了,那么我们就可以使用函数来处理一下刚才获取的路径,下面就是我们的处理:<%=Left(Request.ServerVariables("PATH_TRANSLATED"),instrRev(Request.ServerVariables("PATH_TRANSLATED"),"\"))%>那么这个输出是什么呢?它就是你要的文件所在的目录路径。
$_SERVER[’PHP_SELF’]
http://www.yoursite.com/example/ — – — /example/index.phphttp://www.yoursite.com/example/index.php — – — /example/index.phphttp://www.yoursite.com/example/index.php?a=test — – — /example/index.phphttp://www.yoursite.com/example/index.php/dir/test — – — /dir/test当我们使用$_SERVER['PHP_SELF']的时候,无论访问的URL地址是否有index.php,它都会自动的返回 index.php.但是如果在文件名后面再加斜线的话,就会把后面所有的内容都返回在$_SERVER['PHP_SELF']。
$_SERVER['REQUEST_URI']
http://www.yoursite.com/example/ — – — /http://www.yoursite.com/example/index.php — – — /example/index.phphttp://www.yoursite.com/example/index.php?a=test — – — /example/index.php?a=testhttp://www.yoursite.com/example/index.php/dir/test — – — /example/index.php/dir/test$_SERVER['REQUEST_URI']返回的是我们在URL里写的精确的地址,如果URL只写到”/”,就返回 “/”
$_SERVER['SCRIPT_NAME']
http://www.yoursite.com/example/ — – — /example/index.phphttp://www.yoursite.com/example/index.php — – — /example/index.phphttp://www.yoursite.com/example/index.php — – — /example/index.phphttp://www.yoursite.com/example/index.php/dir/test — – — /example/index.php在所有的返回中都是当前的文件名/example/index.php
转载于:https://www.cnblogs.com/alex-13/p/3506896.html