I'm making a program wich should fetch images (thumbnails or bigger images from thumbnail link) from given url.
Here is my code:
//fetching contents of the file
$file_str = file_get_contents($file);
//regular expression to detect images
$expr = "((\")[a-z0-9\/.\?\=\&](.jpg)[a-z0-9\/.\?\=(href=?[a-z0-9\/.\?\=\&\"]*)";
//saving matches to $matches
preg_match($expr, $file_str, $matches);
//parsing path to page
$parsed_url = parse_url($file);
//making full url to thumbnail image, could be also url to big image
$thumbnail url = $parsed_url['scheme']."://".$parsed_url['host'].substr($parsed_url['path'], 0, strrpos($parsed_url['path'], "/"))."/" .trim($matches[1], "\"");
My problem is that sometimes first image is not a thumbnail, might be backround image or something.
I quess i my problem is that i don't use reqular expression and preg-match function correctly. If someone could help and show me the way. Thanks. :-)