0

全部,

我正在使用 php 中的 simple_html_dom 通过命令提示符访问网页

  $page = file_get_html($url, false, $context); 

其中 $url 是网络 URL。如果您的 URL 类似于http://abc.com/xyz.html?s= "sometext" 那么我得到了正确的响应。但是,如果 URL 在 get 参数(如http://abc.com/xyz.html?s=“some text”)中有空格,我会收到 HTTP/1.1 400 Bad Request 。

谁能帮我解决这个问题。

提前致谢。

4

2 回答 2

2

您需要对参数进行编码:

$text = urlencode('some text');
$url = "http://abc.com/xyz.html?s=$text";
$page = file_get_html($url, false, $context); 
于 2011-10-09T15:46:33.553 回答
0

如果您自己生成该 url,则必须对查询值进行 url_encode:

$url = 'http://example.com/xyz.html?s=' . urlencode('some text');

这会给你

http://example.com/xyz.html?s=some+text
                                  ^---spaces must be + in urls.
于 2011-10-09T15:47:58.910 回答