PHP parsing JSON data, how to add a judgment, URL address is a picture?
I have a set of JSON data, and I want to parse it into HTML format through PHP.
Where the URI part of the picture, there are links. How to add a judgment, is the output of the photo, not the photo is empty. Thank you.
$data = Json_decode ($json), foreach ($data->results as $result) {if (!empty ($result->uri)) { echo ' uri). '"/> ';}}
------Solution--------------------
Most of the image links are in the future, such as the prefix jpg/gif/png.
If it's urlwrite, then you can look at his naming rules to do the filter.
------Solution--------------------
$imgs _arr = array ("JPG", "JPEG", "PNG", "GIF");//The suffix of the picture, you can add $data = Json_decode ($json); foreach ($data->results A s $result) { $ext = Strtolower (End (Explode (".", $result->uri)); if (!empty ($ext) && In_array ($ext, $imgs _arr)) { echo ' uri). ' " /> '; }}
The above is the PHP parsing JSON data, how to add a judge, whether the URL address is the content of the picture, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!