Php 处理get参数中的空格
我使用的命令如下Php 处理get参数中的空格,php,get,Php,Get,我使用的命令如下 $page = file_get_contents($url); 在哪里 $url = "http://www.site.com/search/index.cfm?tab=names&workername=firstname lastname"; 当直接在浏览器中键入url时,chrome会在firstname和lastname之间添加一个%20,网站会正确处理 但是,当我在空格中使用$url时,file\u get\u contents只获取与firstname
$page = file_get_contents($url);
在哪里
$url = "http://www.site.com/search/index.cfm?tab=names&workername=firstname lastname";
当直接在浏览器中键入url时,chrome会在firstname和lastname之间添加一个%20
,网站会正确处理
但是,当我在空格中使用$url时,file\u get\u contents只获取与firstname匹配的结果,并且不知道workername=“firstname lastname”
当我在两者之间显式添加“%20”时,它返回NULL
你的工作是什么
谢谢大家 一些问题:
?
开头,因此不存在,这些变量都不会存在于$\u GET
中%20
编辑:
您试图查询的网站可能会将它们作为GET变量忽略。您是否尝试添加此代码以明确表示它是GET请求
$options = array(
'http' => array('method' => "GET", 'header' => "Accept-language: en\r\n")
);
$context = stream_context_create($options);
file_get_contents($url, false, $context);
您需要在您的文本中添加以下内容:
$fixed= urlencode($workername);
$url = 'http://www.example.com/search/?tab=names&workername='.$fixed;
您是否尝试过
urlencode()
在$url
中插入字符串?在请求后启用错误报告
并检查$http\u response\u header
。这些似乎都不是问题。实际上我有所有这些东西。。由于快速键入导致的错误,基本上忽略了它们。。还有其他想法吗?我添加了一个编辑,但除了这个功能之外,我想不出任何会导致它失败的东西。不过,URL仍需要使用%20
进行编码。您确定名字或姓氏中没有其他字符需要编码吗?我想指出,URL编码还允许“+”作为空格字符的有效编码。
$fixed= urlencode($workername);
$url = 'http://www.example.com/search/?tab=names&workername='.$fixed;