① 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;
}
?>