① php获取url参数
1、在当前网页echo出变量$_SERVER['HTTP_HOST']即可获取域名或主机地址。
② ThinkPHP 网址格式URL地址怎么设置
thinkPHP的URL在config中配置
一、URL规则
1、默认是区分大小写的
2、如果我们不想区分大小写可以改配置文件
'URL_CASE_INSENSITIVE'=>true,//url不区分大小写
3、如果模块名为 UserGroupAction,那么url找模块就必要要写成
http://localhost/thinkphp4/index.php/user_group/index
4、如果'URL_CASE_INSENSITIVE'=>false,那么url也可以写为
http://localhost/thinkphp4/index.php/UserGroup/index
二、URL伪静态
'URL_HTML_SUFFIX'=>'html|shtml|xml',//限制伪静态的后缀
三、URL路由
1、启动路由
要在配置文件中开启路由支持
'URL_ROUTER_ON'=>ture//开启路由
2、使用路由
1.规则表达式配置路由
'URL_ROUTE_RULES'=>array()//路由规则
'my'=>'Index/index',//静态地址路由
'my'=>'/Index/index',//静态地址路由,加/直接跳到网站根目录下。
':id/:num'=>'Index/index',//动态地址路由,可以$_GET接收地址栏参数
'year/:year/:month/:date'=>'Index/index',//动态和静态混合地址路由
'year/:yeard/:monthd/:dated'=>'Index/index',//动态和静态混合地址路由加上d代表类型只能是数字
'my/:id$'=>'Index/index',//加上$说明地址中只能是my/1000后面不能有其他内容了
2.正则表达式配置路由,必须以/开始 /结束
'/^year/(d{4})/(d{2})/(d{2})/'=>'Index/index?year=:1&month=:2&date=:3'//这里d表示必须是数字
③ php打开URL的几种方法
PHP中打开URL地址的几种方法总结,这里的函数主要用于小偷采集等函数。
1:用file_get_contents
以get方式获取内容
复制代码代码如下:
<?php
$url='http://www..com/';
$html=file_get_contents($url);
//print_r($http_response_header);
ec($html);
printhr();
printarr($http_response_header);
printhr();
?>
示例代码2:用fopen打开url,
以get方式获取内容
复制代码代码如下:
<?
$fp=fopen($url,'r');
printarr(stream_get_meta_data($fp));
printhr();
while(!feof($fp)){
$result.=fgets($fp,1024);
}
echo"urlbody:$result";
printhr();
fclose($fp);
?>
示例代码3:用file_get_contents函数,以post方式获取url
复制代码代码如下:
<?php
$data=array('foo'=>
'bar');
$data=http_build_query($data);
$opts=array(
'http'
=>array(
'method'=>'POST',
'header'=>"Content-type:
application/x-www-form-urlencoded".
"Content-Length:".strlen($data).
"",
'content'=>$data
),
);
$context=
stream_context_create($opts);
$html=
file_get_contents('http://localhost/e/admin/test.html',false,$context);
echo$html;
?>
示例代码4:用fsockopen函数打开url,以get方式获取完整的数据,包括header和body
复制代码代码如下:
<?
functionget_url
($url,$cookie=false){
$url=parse_url($url);
$query=
$url[path]."?".$url[query];
ec("Query:".$query);
$fp=fsockopen(
$url[host],$url[port]?$url[port]:80,$errno,$errstr,30);
if(!$fp){
returnfalse;
}else{
$request="GET$queryHTTP/1.1";
$request.="Host:$url[host]";
$request.="Connection:Close";
if($cookie)$request.="Cookie:$cookie ";
$request.="";
fwrite($fp,$request);
while(!@feof($fp)){
$result.=@fgets($fp,
1024);
}
fclose($fp);
return$result;
}
}
//获取url的html部分,去掉header
functionGetUrlHTML($url,$cookie=false){
$rowdata=get_url($url,$cookie);
if($rowdata)
{
$body=
stristr($rowdata,"");
$body=substr($body,4,strlen($body));
return$body;
}
returnfalse;
}
?>