Php call picture garbled problem & lt; meta & nbsp; charsetUTF-8 & gt; & lt ;? Php city name & nbsp; $ city & nbsp; Changsha; & nbsp; obtain json format data & nbsp; $ str & nbsp; & php call picture garbled problem
// City name
$ City = 'Changsha ';
// Obtain data in json format
$ Str = file_get_contents ("http://api.map.baidu.com/telematics/v3/weather? Location = ". $ city." & output = json & ak = KXrZyXh5wUSBEdo5TkgRQkBz ");
// Encode strings in json format
$ Arr = json_decode ($ str, TRUE );
Echo "city:". $ arr ['results'] [0] ['currentcity']. "date:". $ arr ['Date']."
";
$ 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 "weather: {$ val ['weate']}
";
$ 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 ("The image format is not supported ");
}
Echo"
";
// Echo " ";
Echo "wind direction: {$ val ['wind ']}
";
Echo "temperature: {$ val ['temperature ']}
";
}
?>
As shown in the preceding code, garbled characters are output.
Website: http://1.alilo.sinaapp.com/Weather/Weather.php
------ Solution ----------------------
// City name
$ City = "Changsha ";
// Obtain data in json format
$ String = "http://api.map.baidu.com/telematics/v3/weather? Location = ". $ city." & output = json & ak = KXrZyXh5wUSBEdo5TkgRQkBz ";
$ Str = file_get_contents ($ string );
// Echo $ str;
// Encode strings in json format
$ Arr = json_decode ($ str, TRUE );
Foreach ($ arr ['results'] [0] ['weather _ data'] as $ val)
{
Echo $ val ['Date']."
";
Echo "weather: {$ val ['weate']}
";
$ Path = "{$ val ['daypictureurl']}";
Echo '';
Echo"
";
Echo"
";
// Echo " ";
Echo "wind direction: {$ val ['wind ']}
";
Echo "temperature: {$ val ['temperature ']}
";
}
?>