无法打开流:URL中带有感叹号的参数无效

时间:2015-10-02 22:04:10

标签: php google-maps

https://www.google.co.uk/s?tbm=map&fp=1&gs_ri=maps&suggest=p&authuser=0&hl=en&pb=!2i14!4m12!1m3!1d36371.595804441626!2d-2.4949300500000002!3d53.74963355!2m3!1f0!2f0!3f0!3m2!1i1600!2i740!4f13.1!7i10!10b1!12m6!2m3!5m1!2b0!20e3!10b1!16b1!19m10!1e1!1e13!1e2!1e5!1e3!1e10!1e12!1e15!1e27!4smaps_sv.tactile!20m49!1e1!1e13!1e2!1e5!1e11!1e4!1e3!1e10!1e12!1e15!1e27!2m2!1i203!2i100!3m1!2i4!5smaps_sv.tactile!6m3!1m2!1i86!2i86!7m26!1m3!1e1!2b0!3e3!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e3!2b0!3e3!1m3!1e4!2b0!3e3!1m3!1e3!2b1!3e2!2b1!4b1!9b0!22m3!1sJf4OVtPaHMj-UL_-hugD!3b1!7e81!23m1!4b1!26m9!1e12!1e15!1e13!1e3!1e27!2m2!1i80!2i80!4smaps_sv.tactile!37m1!1e81&q=downing%20street&pf=p&tch=1&ech=14&psi=Jf4OVtPaHMj-UL_-hugD.1443823133674.1

当尝试读取上面带有fopen的URL上显示的.txt文件时,它返回无法打开流:无效的参数。

我已尝试过urlencode,但它会出现同样的错误

<?php
$url = "https://www.google.co.uk/s?tbm=map&fp=1&gs_ri=maps&suggest=p&authuser=0&hl=en&pb=!2i14!4m12!1m3!1d36371.595804441626!2d-2.4949300500000002!3d53.74963355!2m3!1f0!2f0!3f0!3m2!1i1600!2i740!4f13.1!7i10!10b1!12m6!2m3!5m1!2b0!20e3!10b1!16b1!19m10!1e1!1e13!1e2!1e5!1e3!1e10!1e12!1e15!1e27!4smaps_sv.tactile!20m49!1e1!1e13!1e2!1e5!1e11!1e4!1e3!1e10!1e12!1e15!1e27!2m2!1i203!2i100!3m1!2i4!5smaps_sv.tactile!6m3!1m2!1i86!2i86!7m26!1m3!1e1!2b0!3e3!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e3!2b0!3e3!1m3!1e4!2b0!3e3!1m3!1e3!2b1!3e2!2b1!4b1!9b0!22m3!1sJf4OVtPaHMj-UL_-hugD!3b1!7e81!23m1!4b1!26m9!1e12!1e15!1e13!1e3!1e27!2m2!1i80!2i80!4smaps_sv.tactile!37m1!1e81&q=downing%20street&pf=p&tch=1&ech=14&psi=Jf4OVtPaHMj-UL_-hugD.1443823133674.1";
$myfile = fopen(urlencode($url), "r") or die("Unable to open file!");
echo $myfile;
fclose($myfile);
?>

1 个答案:

答案 0 :(得分:1)

首先,如果您尝试打开urlencode($url),则可以访问

  

HTTPS%3A%2F%2Fwww.google.co.uk%2FS%3Ftbm%3Dmap%26fp%3D1%26gs_ri%3Dmaps%26suggest%3DP%26authuser%3D0%26hl%3Den%26pb%3D%212i14%214m12 %211立方米%211d36371.595804441626%212D-2.4949300500000002%213d53.74963355%212立方米%211f0%212f0%213f0%213平方米%211i1600%212i740%214f13.1%217i10%2110b1%2112m6%212立方米%215m1%212b0%2120e3%2110b1%2116b1 %2119m10%211e1%211e13%211e2%211e5%211e3%211e10%211e12%211e15%211e27%214smaps_sv.tactile%2120m49%211e1%211e13%211e2%211e5%211e11%211e4%211e3%211e10%211e12%211e15%211e27%212平方米%211i203%212i100%213m1%212i4%215smaps_sv.tactile%216立方米%211平方米%211i86%212i86%217m26%211立方米%211e1%212b0%213e3%211立方米%211e2%212B1%213e2%211立方米%211e2%212b0%213e3%211立方米%211e3 %212b0%213e3%211立方米%211e4%212b0%213e3%211立方米%211e3%212B1%213e2%212B1%214B1%219b0%2122立方米%211sJf4OVtPaHMj-UL_-hugD%213B1%217e81%2123m1%214B1%2126m9%211e12%211e15%211e13 %211e3%211e27%212平方米%211i80%212i80%214smaps_sv.tactile%2137m1%211e81%26Q%3Ddowning%2520street%26pf%3DP%26tch%3D1%26ech%3D14%26psi%3DJf4OVtPaHMj-UL_-hugD.1443823133674.1

这无效。

其次,您的$myfileresource。所以你需要使用它,例如:

$url = "https://www.google.co.uk/s?tbm=map&fp=1&gs_ri=maps&suggest=p&authuser=0&hl=en&pb=!2i14!4m12!1m3!1d36371.595804441626!2d-2.4949300500000002!3d53.74963355!2m3!1f0!2f0!3f0!3m2!1i1600!2i740!4f13.1!7i10!10b1!12m6!2m3!5m1!2b0!20e3!10b1!16b1!19m10!1e1!1e13!1e2!1e5!1e3!1e10!1e12!1e15!1e27!4smaps_sv.tactile!20m49!1e1!1e13!1e2!1e5!1e11!1e4!1e3!1e10!1e12!1e15!1e27!2m2!1i203!2i100!3m1!2i4!5smaps_sv.tactile!6m3!1m2!1i86!2i86!7m26!1m3!1e1!2b0!3e3!1m3!1e2!2b1!3e2!1m3!1e2!2b0!3e3!1m3!1e3!2b0!3e3!1m3!1e4!2b0!3e3!1m3!1e3!2b1!3e2!2b1!4b1!9b0!22m3!1sJf4OVtPaHMj-UL_-hugD!3b1!7e81!23m1!4b1!26m9!1e12!1e15!1e13!1e3!1e27!2m2!1i80!2i80!4smaps_sv.tactile!37m1!1e81&q=downing%20street&pf=p&tch=1&ech=14&psi=Jf4OVtPaHMj-UL_-hugD.1443823133674.1";
$myfile = fopen(($url), "r") or die("Unable to open file!");
echo stream_get_contents($myfile);
fclose($myfile);

或只是

echo file_get_contents($url);