php调用图片乱码问题
<br /><meta charset="UTF-8"><br /><?php<br /> //城市名<br /> $city = '长沙';<br /> //获取json格式的数据<br /> $str = file_get_contents("http://api.map.baidu.com/telematics/v3/weather?location=".$city."&output=json&ak=KXrZyXh5wUSBEdo5TkgRQkBz");<br /> <br /> //对json格式的字符串进行编码<br /> $arr = json_decode($str,TRUE); <br /> <br /> echo "城市:".$arr['results'][0]['currentCity']." 日期:".$arr['date']."<br /><br />";<br /><br /> $wea = "http://1.alilo.sinaapp.com/Weather/0.jpeg";<br /> $weai = imagecreatefromgif($wea);<br /> header("Content-type:image/jpeg");<br /> imagejpeg($weai);<br /> <br /> foreach($arr['results'][0]['weather_data']as $val)<br /> {<br /> echo $val['date']."<br/>";<br /> echo "天气:{$val['weather']}<br/>";<br /> <br /> $path = "{$val['dayPictureUrl']}";<br /> echo "$path";<br /> $imgInfo = getimagesize($path);<br /> $imgType = $imgInfo[2];<br /> switch ($imgType) {<br /> case 1:<br /> $img = imagecreatefromgif($path);<br /> header("Content-type:image/gif");<br /> imagegif($img);<br /> break;<br /> case 2 :<br /> $img = imagecreatefromjpeg($path);<br /> header("Content-type:image/jpeg");<br /> imagejpeg($img);<br /> break;<br /> case 3 :<br /> $img = imagecreatefrompng($path);<br /> header("Content-type:image/png");<br /> imagepng($img);<br /> break; <br /> default:<br /> exit("图片格式不支持");<br /> } <br /> echo "<br/>";<br /> // echo "< img src = "{$val['dayPictureUrl']}" />";<br /> echo "风向:{$val['wind']}<br/>";<br /> echo "温度:{$val['temperature']}<br/><br />";<br /> }<br />?><br />
<br /><meta charset="UTF-8"><br /><?php<br /> //城市名<br /> $city = "长沙";<br /> //获取json格式的数据<br /> $string ="http://api.map.baidu.com/telematics/v3/weather?location=".$city."&output=json&ak=KXrZyXh5wUSBEdo5TkgRQkBz";<br /> $str = file_get_contents($string);<br /> <br /> //echo $str;<br /> //对json格式的字符串进行编码<br /> $arr = json_decode($str,TRUE); <br /> <br /> <br /> foreach($arr['results'][0]['weather_data']as $val)<br /> {<br /> echo $val['date']."<br/>";<br /> echo "天气:{$val['weather']}<br/>";<br /> <br /> $path = "{$val['dayPictureUrl']}";<br /> echo '<img src="'.$path.'" alt="php调用图片乱码有关问题" >';<br /> echo "<br/>";<br /> echo "<br/>";<br /> // echo "< img src = "{$val['dayPictureUrl']}" />";<br /> echo "风向:{$val['wind']}<br/>";<br /> echo "温度:{$val['temperature']}<br/><br />";<br /> <br /> } <br /> <br /> <br />?><br />