Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么这个get参数不等于字符串?_Php - Fatal编程技术网

Php 为什么这个get参数不等于字符串?

Php 为什么这个get参数不等于字符串?,php,Php,给定一个url: scrape.php?u=http%3A%2F%2Fwww.colvillebanker.com%2Fagent%3…等 $url = $_GET['u']; $url2 = 'http://www.coldwellbanker.com/agent?action=detail&agentId=121759&mode=detail'; var_dump($url==$url2); //This prints out bool(false) 为什么$\u GET

给定一个url:

scrape.php?u=http%3A%2F%2Fwww.colvillebanker.com%2Fagent%3…等

$url = $_GET['u'];
$url2 = 'http://www.coldwellbanker.com/agent?action=detail&agentId=121759&mode=detail';
var_dump($url==$url2);

//This prints out bool(false)

为什么$\u GET参数与单引号中的等效字符串不同?

问题在于,您传递它的URL认为&实际上是原始脚本的参数:

因此,如果你这样做:

<?php echo $_GET['u'];?> 
以下是我所做的:

给定一个URL:

http://localhost/gettest.php?u=http%3A%2F%2Fgoogle.com%3Ftest%3Dtest
这个脚本:

$url = $_GET['u'];
var_dump($url);
$url2 = "http://google.com?test=test&test1=test1";
var_dump($url2);
var_dump($url == $url2);
输出为:

string 'http://google.com?test=test' (length=27)
string 'http://google.com?test=test&test1=test1' (length=39) 
boolean false

这让我相信,符号是由$进行评估的,而$是一个单独的参数。也许你应该对你的URL进行Base64编码,以确保它能正常工作

您是否直接在
$url
上尝试了
var\u dump()
?是的。这很奇怪。$url的var_dump为我提供字符串(84),而$url2的var_dump为我提供字符串(76),因为您获得的字符太多(或2乘以4),您的'scrape.php?u=…'调用是否可能使用了
&
而不是
&
?php调用是什么意思?我只是在解码一个用php编码的url。。。i、 不使用任何html实体,但我喜欢这个想法$_GET变量已通过url_解码,根据发现的问题。改变了我的回答我想这可能是问题所在,但如果我打印r($);它只是给了我[u]=等等。。基本上,我的意思是,它没有拉出参数
$url=end(explode('u=',$\u SERVER['argv'][0])
正如预期的那样,使用base64_encode()对字符串进行编码将确保它通过$_GET正确传输。您的意思是URL将进行base64编码吗。比如scrap.php?u=BASE64ENCODEDSTRING。然后我能解码结果吗?
http://localhost/gettest.php?u=http%3A%2F%2Fgoogle.com%3Ftest%3Dtest
$url = $_GET['u'];
var_dump($url);
$url2 = "http://google.com?test=test&test1=test1";
var_dump($url2);
var_dump($url == $url2);
string 'http://google.com?test=test' (length=27)
string 'http://google.com?test=test&test1=test1' (length=39) 
boolean false