Check Page For Images

Discussion in 'PHP' started by leon_king, May 23, 2007.

  1. #1
    hi guys,

    I really need help on how to check the page (html page) for images / image file and display the url of the images.
    I'm searching for almost a week for the sample code but i can't
    find anything. What are the syntax that im going to use?

    Please help me with this I badly need this in my project.

    Thanks in Advance. :)
     
    leon_king, May 23, 2007 IP
  2. xooMan

    xooMan Peon

    Messages:
    92
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I have just written and tried this code:

    
    <?php
    // Get page srouce
    $s = file_get_contents('actual_url_to_the_page');
    $pattern = '/<img[^>]+src=([\'"]?)([^>"\']+)\1[^>]*\/>/is';
    
    // Apply regexp pattern to the content
    preg_match_all($pattern, $s, $matches);
    
    // Print URLs
    print_r($matches[2]);
    ?>
    
    PHP:
    The key is preg_match_all() function call with the corresponding pattern.
     
    xooMan, May 23, 2007 IP