Welcome Guest, Not a member yet? Register   Sign In
Identifying images referenced in HTML
#8

[eluser]TheFuzzy0ne[/eluser]
This function should be a good start. It's only been briefly tested. Please let me know if you want anything else added. Simply pass the function the HTML source for the page. If no images are found, then an empty array is returned (but this won't necessarily mean there aren't any on the page). Please be advised that some Web sites use JavaScript to display their images, and they do this so you can't scrape them. I'm relying on you to test the function out.

Code:
function get_img_names($html_source) {
        $arr = array();
        $pattern = '/\<img *src=[\'\"]{0,1}([^\"\'\s]+).+\/\>/';

        preg_match_all($pattern, $html_source, $matches);

        foreach ($matches[1] as $match)
        {
                $filename = basename($match);
                if (in_array($filename)) { continue; }
                $arr[] = $filename;
        }

        return $arr;
}

One more note. The script doesn't check to see what the file extension is, and whether the src attribute value is a server query string. I trust you can modify it a bit to do that.


Messages In This Thread
Identifying images referenced in HTML - by El Forum - 02-09-2009, 03:16 PM
Identifying images referenced in HTML - by El Forum - 02-09-2009, 03:26 PM
Identifying images referenced in HTML - by El Forum - 02-09-2009, 03:28 PM
Identifying images referenced in HTML - by El Forum - 02-09-2009, 03:50 PM
Identifying images referenced in HTML - by El Forum - 02-09-2009, 04:53 PM
Identifying images referenced in HTML - by El Forum - 02-09-2009, 07:09 PM
Identifying images referenced in HTML - by El Forum - 02-09-2009, 07:12 PM
Identifying images referenced in HTML - by El Forum - 02-09-2009, 08:01 PM
Identifying images referenced in HTML - by El Forum - 02-09-2009, 08:03 PM
Identifying images referenced in HTML - by El Forum - 02-09-2009, 08:07 PM
Identifying images referenced in HTML - by El Forum - 02-09-2009, 09:34 PM



Theme © iAndrew 2016 - Forum software by © MyBB