代码如上所示,输出来的是一串乱码。 网站:http://1.alil">
时间:2021-07-01 10:21:17 帮助过:15人阅读
"; $wea = "http://1.alilo.sinaapp.com/Weather/0.jpeg"; $weai = imagecreatefromgif($wea); header("Content-type:image/jpeg"); imagejpeg($weai); foreach($arr['results'][0]['weather_data']as $val) { echo $val['date']."
"; echo "天气:{$val['weather']}
"; $path = "{$val['dayPictureUrl']}"; echo "$path"; $imgInfo = getimagesize($path); $imgType = $imgInfo[2]; switch ($imgType) { case 1: $img = imagecreatefromgif($path); header("Content-type:image/gif"); imagegif($img); break; case 2 : $img = imagecreatefromjpeg($path); header("Content-type:image/jpeg"); imagejpeg($img); break; case 3 : $img = imagecreatefrompng($path); header("Content-type:image/png"); imagepng($img); break; default: exit("图片格式不支持"); } echo "
"; // echo "< img src = "{$val['dayPictureUrl']}" />"; echo "风向:{$val['wind']}
"; echo "温度:{$val['temperature']}
"; }?>
你在一个页面中输出了两种类型的数据,浏览器不知道怎么把他们分开。于是就 乱码了
你需要将
$wea = "http://1.alilo.sinaapp.com/Weather/0.jpeg";
$weai = imagecreatefromgif($wea);
header("Content-type:image/jpeg");
imagejpeg($weai);
改为
echo '';
如果你确实想通过抓取图片的方式了完成,那么需要将那4行单独写成文件,比如 https://www.gxlcms.com/wea.php
然后通过标记
去调用
你在一个页面中输出了两种类型的数据,浏览器不知道怎么把他们分开。于是就 乱码了
你需要将
$wea = "http://1.alilo.sinaapp.com/Weather/0.jpeg";
$weai = imagecreatefromgif($wea);
header("Content-type:image/jpeg");
imagejpeg($weai);
改为
echo '';
如果你确实想通过抓取图片的方式了完成,那么需要将那4行单独写成文件,比如 https://www.gxlcms.com/wea.php
然后通过标记
去调用
你不都是
$img = imagecreatefromgif($path);
header("Content-type:image/gif");
imagegif($img);
这样的吗?
一样的问题就不会举一反三吗?
"; echo "天气:{$val['weather']}
"; $path = "{$val['dayPictureUrl']}"; echo ''; echo "
"; echo "
"; // echo "< img src = "{$val['dayPictureUrl']}" />"; echo "风向:{$val['wind']}
"; echo "温度:{$val['temperature']}
"; } ?>
"; echo "天气:{$val['weather']}
"; $path = "{$val['dayPictureUrl']}"; echo ''; echo "
"; echo "
"; // echo "< img src = "{$val['dayPictureUrl']}" />"; echo "风向:{$val['wind']}
"; echo "温度:{$val['temperature']}
"; } ?>