導航:首頁 > 編程語言 > phparrayurl

phparrayurl

發布時間:2024-10-20 19:19:11

php如何將數組轉URL參數

PHP如何將數組轉URL參數
1、使用PHP內置函數「http_build_query()」將字元串轉為URL參數;
使用示例:
<php$data = array( 'foo' => 'bar' 'baz' => 'boom' 'cow' => 'milk' 'php' => 'hypertext processor');echo http_build_query($data) . "\n"echo http_build_query($data, '' '&');>
輸出結果:
foo=bar&baz=boom&cow=milk&php=hypertext+processorfoo=bar&baz=boom&cow=milk&php=hypertext+processor
2、根據URL參數規律使用循環將數組進行拼接,鍵和值使用「=」進行拼接數組單元使用「&」進行拼接即可。
簡單示例:
function array_to_url_prarm($array){ $prarms = []; foreach ($array as $key => $val) { $prarms[] = $key . '=' . str_replace(' ' '+' $val); } return implode('&' $prarms);}
推薦教程:《PHP教程》

Ⅱ php語言里的一些很簡單的代碼解釋。求解釋

第一行,將關鍵字和指向的頁面裝入一個數組,可用做url鏈接,portal指向portal.php
第二行,用點分割指定的系統變數$_SERVER['HTTP_HOST']
第三行,是一個url鏈接,目標頁面為forum.php。在?後面傳遞「變數=值」對(如:mod=group),
&用來連接這些變數和值對。
第四行,是一組嵌套的三元運算符。類似於if...else判斷。
*****
表達式1?表達式2:表達式3
(1)條件表達式的執行順序:先求解表達式1,若為非0(真)則求解表達式2,此時表達式2的值就作為整個表達式的值。
若表達式1的值為0(假),則求解表達式3,表達式3的值就是整個條件表達式的值。
(2)條件表達式優先於賦值運算符,max=(a>b)?a:b則先求解條件表達式在賦給max。
(3)自右向左運算
a>b? a:c>d? c:d
應該是
a>b? a:(c>d? c:d)
******
最好不要在php中使用多個三元操作符。
使用多個時添加括弧:
$a=1>0?1:(2==0?2:(3<0?3:0));

Ⅲ php怎麼獲取域名之後的url

1,$_SERVER["QUERY_STRING"]
說明:查詢(query)的字元串

2,$_SERVER["REQUEST_URI"]
說明:訪問此頁面所需的URI

3,$_SERVER["SCRIPT_NAME"]
說明:包含當前腳本的路徑

4,$_SERVER["PHP_SELF"]
說明:當前正在執行腳本的文件名

實例:
1,http://www.biuuu.com/ (直接打開主頁)
結果:
$_SERVER["QUERY_STRING"] = ""
$_SERVER["REQUEST_URI"] = "/"
$_SERVER["SCRIPT_NAME"] = "/index.php"
$_SERVER["PHP_SELF"] = "/index.php"

2,http://www.biuuu.com/?p=222 (附帶查詢)
結果:
$_SERVER["QUERY_STRING"] = "p=222"
$_SERVER["REQUEST_URI"] = "/?p=222"
$_SERVER["SCRIPT_NAME"] = "/index.php"
$_SERVER["PHP_SELF"] = "/index.php"

3,http://www.biuuu.com/index.php?p=222&q=biuuu
結果:
$_SERVER["QUERY_STRING"] = "p=222&q=biuuu"
$_SERVER["REQUEST_URI"] = "/index.php?p=222&q=biuuu"
$_SERVER["SCRIPT_NAME"] = "/index.php"
$_SERVER["PHP_SELF"] = "/index.php"

$_SERVER["QUERY_STRING"]獲取查詢語句,實例中可知,獲取的是?後面的值
$_SERVER["REQUEST_URI"] 獲取http://www.biuuu.com後面的值,包括/
$_SERVER["SCRIPT_NAME"] 獲取當前腳本的路徑,如:index.php
$_SERVER["PHP_SELF"] 當前正在執行腳本的文件名

當前url:"http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF']

總結一下,對於QUERY_STRING,REQUEST_URI,SCRIPT_NAME和PHP_SELF,深入了解將有利於我們在$_SERVER函數中正確調用這四個值。通過實例詳解$_SERVER函數中QUERY_STRING,REQUEST_URI,SCRIPT_NAME和PHP_SELF掌握四個變數之間的區別。

$_SERVER["REQUEST_URI"] :獲取當前請求的完整的(除域名的)url。。。

uchome系統中處理技巧:

代碼
//處理REQUEST_URI
if(!isset($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
if(isset($_SERVER['QUERY_STRING'])) $_SERVER['REQUEST_URI'] .= '?'.$_SERVER['QUERY_STRING'];
}
if($_SERVER['REQUEST_URI']) {
$temp = urldecode($_SERVER['REQUEST_URI']);
if(strexists($temp, '<') || strexists($temp, '"')) {
$_GET = shtmlspecialchars($_GET);//XSS
}
}

代碼如下:

代碼
<?php
echo $_SERVER['DOCUMENT_ROOT']."<br>"; //獲得伺服器文檔根變數
echo $_SERVER['PHP_SELF']."<br>"; //獲得執行該代碼的文件伺服器絕對路徑的變數
echo __FILE__."<br>"; //獲得文件的文件系統絕對路徑的變數
echo dirname(__FILE__); //獲得文件所在的文件夾路徑的函數
?>

//server函數
$_SERVER["HTTP_REFERER"]=http://localhost/lianxi/
$_SERVER["HTTP_ACCEPT_LANGUAGE"]=zh-cn
$_SERVER["HTTP_ACCEPT_ENCODING"]=gzip, deflate
$_SERVER["HTTP_USER_AGENT"]=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727)
$_SERVER["HTTP_HOST"]=localhost
$_SERVER["HTTP_CONNECTION"]=Keep-Alive
$_SERVER["PATH"]=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Common Files\Adobe\AGL;C:\Program Files\MySQL\MySQL Server 5.0\bin;C:\php;C:\php\ext
$_SERVER["SystemRoot"]=C:\WINDOWS
$_SERVER["COMSPEC"]=C:\WINDOWS\system32\cmd.exe
$_SERVER["PATHEXT"]=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
$_SERVER["WINDIR"]=C:\WINDOWS
$_SERVER["SERVER_SIGNATURE"]=
Apache/2.0.55 (Win32) PHP/5.1.1 Server at localhost Port 80 \\使用的何伺服器
$_SERVER["SERVER_SOFTWARE"]=Apache/2.0.55 (Win32) PHP/5.1.1
$_SERVER["SERVER_NAME"]=localhost \\伺服器名稱
$_SERVER["SERVER_ADDR"]=127.0.0.1
$_SERVER["SERVER_PORT"]=80 \\伺服器埠
$_SERVER["REMOTE_ADDR"]=127.0.0.1
$_SERVER["DOCUMENT_ROOT"]=D:/lianxi \\網站的主目錄
$_SERVER["SERVER_ADMIN"][email protected] \\安裝APACHE時設置的郵箱
$_SERVER["SCRIPT_FILENAME"]=D:/lianxi/lianxi/servervalues.php \\當前的網頁的絕對路徑,
$_SERVER["REMOTE_PORT"]=1076 \\遠程埠
$_SERVER["GATEWAY_INTERFACE"]=CGI/1.1
$_SERVER["SERVER_PROTOCOL"]=HTTP/1.1
$_SERVER["REQUEST_METHOD"]=GET
$_SERVER["QUERY_STRING"]=\\獲取?號後面的內容
$_SERVER["REQUEST_URI"]=例子:/lianxi/servervalues.php?a=1&b=2
$_SERVER["SCRIPT_NAME"]=例子:/lianxi/servervalues.php
$_SERVER["PHP_SELF"]=/lianxi/servervalues.php \\返回當前網頁的相對路徑.
$_SERVER["REQUEST_TIME"]=1179190013 \\運行時間 單位為十萬分之一毫秒
$_SERVER["argv"]=Array
$_SERVER["argc"]=0
1,$_SERVER["QUERY_STRING"]
說明:查詢(query)的字元串
2,$_SERVER["REQUEST_URI"]
說明:訪問此頁面所需的URI
3,$_SERVER["SCRIPT_NAME"]
說明:包含當前腳本的路徑
4,$_SERVER["PHP_SELF"]
說明:當前正在執行腳本的文件名
實例:
1,http://www.biuuu.com/ (直接打開主頁)
結果:
$_SERVER["QUERY_STRING"] = 「」
$_SERVER["REQUEST_URI"] = 「/」
$_SERVER["SCRIPT_NAME"] = 「/index.php」
$_SERVER["PHP_SELF"] = 「/index.php」
2,http://www.biuuu.com/?p=222 (附帶查詢)
結果:
$_SERVER["QUERY_STRING"] = 「p=222″
$_SERVER["REQUEST_URI"] = 「/?p=222″
$_SERVER["SCRIPT_NAME"] = 「/index.php」
$_SERVER["PHP_SELF"] = 「/index.php」
3,http://www.biuuu.com/index.php?p=222&q=biuuu
結果:
$_SERVER["QUERY_STRING"] = 「p=222&q=biuuu」
$_SERVER["REQUEST_URI"] = 「/index.php?p=222&q=biuuu」
$_SERVER["SCRIPT_NAME"] = 「/index.php」
$_SERVER["PHP_SELF"] = 「/index.php」
$_SERVER["QUERY_STRING"]獲取查詢語句,實例中可知,獲取的是?後面的值
$_SERVER["REQUEST_URI"] 獲取http://www.biuuu.com後面的值,包括/
$_SERVER["SCRIPT_NAME"] 獲取當前腳本的路徑,如:index.php
$_SERVER["PHP_SELF"] 當前正在執行腳本的文件名

代碼
<?php
/**
__FILE__ ,
getcwd(),
$_SERVER["REQUEST_URI"],
$_SERVER["SCRIPT_NAME"],
$_SERVER["PHP_SELF"],
$_SERVER["SCRIPT_FILENAME"],

來觀察一下這些變數或函數的異同.
假設有一個請求地址為: http://localhost:8080/test.php/age=20
而test.php 的完整路徑是: D:/server/www/example/test.php
1) getcwd()
將得到瀏覽器請求的頁面文件所在的目錄. 即test.php 文件所在的目錄: D:/server/www/example/ ,
如果在test.php 執行了 require 或 include 語句, 比如 inculde(」test_dir/test2.php」),
那麼在 test2.php 里 getcwd()函數 返回的也將是 test.php 所在的目錄.
2) __FILE__
一個魔術變數, 用它將得到 __FILE__ 變數所在文件的完整路徑,
比如: test.php 里 __FILE__ 將得到 D:/server/www/example/test.php ,
test_dir/test2.php 里的 __FILE__ 將得到 D:/server/www/example/test_dir/test2.php

3) $_SERVER["SCRIPT_FILENAME"]
將得到瀏覽器請求的頁面文件的完整路徑.
test.php 和 test_dir/test2.php 里用 $_SERVER["SCRIPT_NAME"] 都將得到 D:/server/www/example/test.php.

4) $_SERVER["SCRIPT_NAME"]
將得到瀏覽器請求的頁面文件的文件名,注意: 與 $_SERVER["SCRIPT_NAME"] 不同, 此變數只得到文件名而不包含路徑,
在test.php 與 test_dir/test2.php 用$_SERVER["SCRIPT_NAME"] 得到的都將是 test.php.
當然, 在test.php 與 test_dir/test2.php 執行 basename($_SERVER["SCRIPT_FILENAME"]) 與 $_SERVER["SCRIPT_NAME"] 相同.
執行 在test.php 與 test_dir/test2.php 執行 realpath(」test.php」) 得到的結果與 $_SERVER["SCRIPT_FILENAME"] 相同.

5) $_SERVER["PHP_SELF"]
將得到瀏覽器請求頁面的文件名, 並剝掉問號 ? 後的內容, 注意:不包含路徑,
比如在客戶端里請求 http://localhost:8080/test.php?age=20&name=Tom,
那麼test.php 和 test_dir/test2.php 的 $_SERVER["PHP_SELF"] 都將得到 「test.php」。「age=20&name=Tom」被剝掉。
而如果客戶端里請求 http://localhost:8080/test.php/age=20&name=Tom,
那麼test.php 和 test_dir/test2.php 的 $_SERVER["PHP_SELF"] 都將得到 「test.php/age=20&name=Tom」。

6) $_SERVER["REQUEST_URI"]
將得到瀏覽器請求頁面的文件名, 以及文件名之後的所有內容(注意: 井號 # 之後的內容將被略去),
比如在客戶端里請求 http://localhost:8080/test.php?age=20&name=Tom,
那麼test.php 和 test_dir/test2.php 的 $_SERVER["REUEST_URI"] 都將得到 「test.php」。「age=20&name=Tom」被剝掉。
而如果客戶端里請求 http://localhost:8080/test.php/age=20&name=Tom,
那麼test.php 和 test_dir/test2.php 的 $_SERVER["REQUEST_URI"] 都將得到 「test.php/age=20&name=Tom」。
*/

// test.php:
echo 「test1.php variables <br />」;
echo 「getcwd: 「, getcwd(), 「<br />」;
echo 「__FILE__: 「, __FILE__, 「<br />」;
echo 「REQUEST_URI: 「, $_SERVER["REQUEST_URI"], 「<br />」;
echo 「SCRIPT_NAME: 「, $_SERVER["SCRIPT_NAME"], 「<br />」;
echo 「PHP_SELF: 「, $_SERVER["PHP_SELF"], 「<br />」;
echo 「SCRIPT_FILENAME 「, $_SERVER["SCRIPT_FILENAME"] , 「<br />」;

// 把 test2.php 包含進來, 在 test2.php 里輸出上面的變數,看有什麼不同:
include_once(」test2/test2.php」);

?>

Ⅳ 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;
}

?>

Ⅳ php接收表單數據存儲數組,並按格式輸出

可以先接收到值。然後組裝成
123,456,789 這樣的字元串存入數脊知據庫
然後頃兄讀取資料庫的時候,用explode() 把他轉為櫻乎消數組,在循環輸出就可以了

$url1 = $_POST('url1');

$url2 = $_POST('url2');

$url3 = $_POST('url3');
組裝數據
$str = $url1.",".$url2.",";
然後將$str 存入資料庫
然後你讀取這條數據。讀出來是這樣的
$new_str = "123,456,789 ";
然後
$array = explode(',',$new_str);
var_mp($array);

Ⅵ 用PHP正則將任何URL從文章中匹配出來,例如:http://.baidu.com/qct=17&pn=0&tn=ikask&rn=12&word

`I shall have my supper in another room,' I said. `Have you no place you call a parlour?'
`Parlour!' he echoed sneeringly, `parlour! Nay, we've noa parlours. If yah nnut loike wer company, there's maister's; un' if yah nnut loike maister, there's us.
`Then I shall go upstairs!' I answered; `show me a chamber.' I put my basin on a tray, and went myself to fetch some more milk. With great grumblings, the fellow rose, and preceded me in my ascent: we mounted to the garrets; he opening a door, now and then, to look into the apartments we passed.
`Here's a rahm,' he said, at last, flinging back a cranky board on hinges. `It's weel eneugh tuh ate a few porridge in. They's a pack o' corn i' t' corner, thear, meeterly clane; if yah're feared uh muckying yer grand silk cloes, spread yer hankerchir o' t' top on't.'
The `rahm' was a kind of lumber-hole smelling strong of malt and grain; various sacks of which articles were piled around, leaving a wide, bare space in the middle.
`Why, man!' I exclaimed, facing him angrily,coach outlet, `this is not a place to sleep in. I wish to see my bedroom.
`Bed-rume!' he repeated, in a tone of mockery. `Yah's see all t' bed-rumes thear is--yon's mine.'
He pointed into the second garret, only differing from the first in being more naked about the walls, and having a large, low, curtainless bed, with an indigo-coloured quilt at one end.
`What do I want with yours?' I retorted. `I suppose Mr Heathcliff does not lodge at the top of the house, does he?'
`Oh! it's Maister Hathecliff's yah're wenting!' cried he, as if making a new discovery. `Couldn't ye uh said soa, at onst? un then, Aw mud uh telled ye, baht all this wark,christian louboutin uk, ut that's just one yah cannut sea--he alIas keeps it locked, un nob'dy iver mells on't but hisseln.'
`You've a nice house, Joseph,' I could not refrain from observing, `and pleasant inmates; and I think the concentrated essence of all the madness in the world took up its abode in my brain the day I linked my fate with theirs! However, that is not to the present purpose--there are other rooms. For heaven's sake be quick, and let me settle somewhere!'
He made no reply to this adjuration; only plodding doggedly down the wooden steps, and halting before an apartment which, from that halt and the superior quality of its furniture, I conjectured to be the best one. There was a carpet: a good one, but the pattern was obliterated by st; a fireplace hung with cut paper, dropping to pieces; a handsome oak bedstead with ample crimson curtains of rather expensive material and modern make; but they had evidently experienced rough usage: the valances hung in festoons, wrenched from their rings, and the iron rod supporting them was bent in an arc on one side, causing the drapery to trail upon the floor. The chairs were also damaged, many of them severely; and deep indentations deformed the panels of the walls. I was endeavouring to gather resolution for entering and taking possession, when my fool of a guide announced, `This here is t' maister's.' My supper by this time was cold, my appetite gone,clarks shoes, and my patience exhausted. I insisted on being provided instantly with a place of refuge,clarks shoes uk, and means of repose.

Ⅶ php 兩個數組,組合到一起

就是用array_merg來組合數組

$arr1=Array("Price" => 100,"Count" => 2);
$arr2=Array("Price" => 68,"Count" => 1);
$arr3=Array("ImageUrl" => "http://www..com/uploads/r/roynyj1423816159/3/4/d/a/thumb_54e05b04e4e1c.jpg","ItemName" => "藍瑪瑙","ItemDescription" =>"");
$arr4=Array("ImageUrl" => "http://www..com/uploads/r/roynyj1423816159/d/1/a/f/thumb_54e0609cb71b0.jpg","ItemName" => "可調大小硃砂雙魚手串","ItemDescription" =>"");
$data1=array_merge($arr1,$arr3);
$data2=array_merge($arr2,$arr4);
$datas=Array("7"=>$data1,"11"=>$data2);
print_r($datas);

閱讀全文

與phparrayurl相關的資料

熱點內容
公司20台電腦如何訪問伺服器 瀏覽:810
土的壓縮指標主要 瀏覽:892
php日誌類庫 瀏覽:975
微信骰子的演算法 瀏覽:61
風暴英雄伺服器地址怎麼配 瀏覽:750
現代密碼仿射變換編程代碼 瀏覽:250
餓了么是用什麼app 瀏覽:328
寧波市家庭共濟用什麼app 瀏覽:708
怎麼配置一個小型伺服器 瀏覽:330
net命令有什麼用 瀏覽:952
juniper重啟命令 瀏覽:717
匯編圖形編程 瀏覽:93
檢查ping命令 瀏覽:166
駕校報名的app叫什麼 瀏覽:979
阿里雲伺服器網站打不開 瀏覽:372
京東app數字是什麼字體 瀏覽:459
蘋果的伺服器有什麼用 瀏覽:590
java資料庫編程寶典 瀏覽:538
翻譯編程技術文檔 瀏覽:340
冰箱壓縮端子阻值一樣 瀏覽:283