PHP parses JSON data, how to add a judgment, whether the URL address is an image

Source: Internet
Author: User
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). '"/> ';}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.