php数组url
1. php里面怎么根据URL参数得到制定数组
您好
query_string中的参数不可能是数组啊。
print_r($_GET);你会明白更多。
希望回答对你有帮助,如果有疑问,请继续追问
答题不易,互相理解,您的采纳是我前进的动力,感谢您。
2. php编程将url地址转换转换数组
<?php
$str="http://www.jb51.net/yunying/29357.html";
$arr=array();
$arr=explode("/",$str);
var_mp($arr);
?>
3. 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;
}
?>
4. php输出数组
<?php
function get_all_url($code){
preg_match_all('/<a\s+href=["|\']?([^>"\' ]+)["|\']?\s*[^>]*>([^>]+)<\/a>/i',$code,$arr);
return array('name'=>$arr[2],'url'=>$arr[1]);
}
//---------------------------------------------------以上是你的函数部分
$code="这里写你的url地址"; //这儿写你要匹配的url地址
$arr=get_all_url($code);//调用函数,所得的值赋给$arr,得到的$arr是一个数组
foreach($arr as $key=>$value){//循环得到的数组,其中键赋给变量$key,值赋给$value
echo $key."=>".$value;//向浏览器输出键和值,“键=>值”
}
?>
不明白再议
5. PHP里面怎么根据URL参数得到制定数组
不明觉历。。。
大哥能否把问题描述清楚一点再来提问
6. php中我想用url来传递数组
首先你这种方式不安全,千万不要用在正式服务器上。
GET方式 test.php?xxx[]=1&xxx[]=2&xxx[]=3&xxx[]=a&xxx[]=b&xxx[]=c
<?php
print_r($_GET['xxx']);
foreach($_GET['xxx'] as $k=>$v){
include $v;
}
7. php里那个函数可以把url里的参数给分成数组,打印出来呢
<?php
$url="http://www.xyz.com?x=5&y=6";
$arr=explode("?",$url);
echo $arr[1];
?>
好久没去用PHP了,有错误的话用哪个函数调试一下。
8. php如何判断一个数组中是否存在于一段url中
有专门的函数,不要用for循环,系统函数能实现快速搜索:
in_array
(PHP 4, PHP 5)
in_array — 检查数组中是否存在某个值
说明
bool in_array ( mixed $needle, array $haystack [, bool $strict] )
在 haystack 中搜索 needle,如果找到则返回 TRUE,否则返回 FALSE。
如果第三个参数 strict 的值为 TRUE 则 in_array() 函数还会检查 needle 的类型是否和 haystack 中的相同。
注意: 如果 needle 是字符串,则比较是区分大小写的。
注意: 在 PHP 版本 4.2.0 之前,needle 不允许是一个数组。
例 292. in_array() 例子
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
第二个条件失败,因为 in_array() 是区分大小写的,所以以上程序显示为:
Got Irix
例 293. in_array() 严格类型检查例子
<?php
$a = array('1.10', 12.4, 1.13);
if (in_array('12.4', $a, true)) {
echo "'12.4' found with strict check\n";
}
if (in_array(1.13, $a, true)) {
echo "1.13 found with strict check\n";
}
?>
上例将输出:
1.13 found with strict check
例 294. in_array() 中用数组作为 needle
<?php
$a = array(array('p', 'h'), array('p', 'r'), 'o');
if (in_array(array('p', 'h'), $a)) {
echo "'ph' was found\n";
}
if (in_array(array('f', 'i'), $a)) {
echo "'fi' was found\n";
}
if (in_array('o', $a)) {
echo "'o' was found\n";
}
?>
上例将输出:
'ph' was found
'o' was found
9. PHP里一个数组有 url-1.html,url-2.html,……怎么替换成url-1-add.html,url-2-add.html……
$array = array(‘url-1.html’,‘url-2.html’,‘url-3.html’,‘url-4.html’);
foreach($array as $k=>$v){
$array[$k] = str_ireplace('.html','-add.html',$v);
}
10. php 中有将数组构造url参数的方法build_query,那请问将该url参数还原为php数组的方法有没有啊
通常我们这样自己写加密函数:
把你的要加密的变量,与一个key(任意字符串)拼接到一块 然后使用url_encode 或者base64
等可逆函数加密,加密后还可再选择去掉第几位的第一个字符,添加哪位的字符,把你的加密过程做个反解函数就行了