PHP parsing JSON data, how to add a judge, whether the URL address is a picture

Source: Internet
Author: User
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.

    • PHP Code
$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--------------------

    • PHP Code
$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)!


  • Related Article

    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.