PHP parses JSON data. how does one add a judgment that whether the URL address is an image? I have a set of JSON data. I want to parse it into HTML content through PHP. The Uri part contains photos and links. How to add a judgment is the output of the photo, not the empty photo. Thank you. PHPcode $ data = json_decode ($ json); foreach PHP parses JSON data. how can I add a judgment that whether the URL address is an image?
I have a set of JSON data. I want to parse it into HTML content through PHP.
The Uri part contains photos and links. How to add a judgment is the output of the photo, not the empty photo. Thank you.
PHP code
$data = json_decode($json);foreach ($data->results as $result) {if(!empty($result->Uri)){ echo 'Uri).'" />';}}
------ Solution --------------------
Most image links are suffixed with jpg, gif, or png.
If urlwrite is used, you can check its naming rules for filter.
------ Solution --------------------
PHP code
$ Imgs_arr = array ("jpg", "jpeg", "png", "gif"); // you can add $ data = json_decode ($ json) to the image suffix ); foreach ($ data-> results as $ result) {$ ext = strtolower (end (explode (". ", $ result-> Uri); if (! Empty ($ ext) & in_array ($ ext, $ imgs_arr) {echo 'uri). '"/> ';}}