导航:首页 > 编程语言 > 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相关的资料

热点内容
为什么燕窝溯源码可以更改经销商 浏览:949
和服务器连接的交换机叫什么 浏览:773
苹果手机如何设置服务器 浏览:934
迅雷下载游戏需要解压 浏览:853
3d平滑命令 浏览:41
必须去车管所解压 浏览:387
室友命令我 浏览:311
lol全部命令 浏览:40
用什么APP查指数 浏览:921
什么是作品源码 浏览:671
我的理想程序员该怎么写 浏览:842
英译中国现代散文选pdf 浏览:448
装饰设计模式java 浏览:23
linuxshell清屏命令 浏览:136
惠利app是什么 浏览:779
游戏端口读取服务器失败怎么弄 浏览:878
linux修复mbr 浏览:128
磁盘格式化基本命令 浏览:578
程序员掉入异世界 浏览:954
andlua画质助手源码 浏览:577