Home > Programming > Preg_match_all Help

Preg_match_all Help

December 1st, 2009

I want to match an image name with the page source
__________________________________________

$name = “fox hat jumps jpg”; //eg fox hat jumps jpg
$name_end = trim(substr(strrchr($name,” “),1)); //returns jpg
$end= trim(str_replace($name_end, ”,$name)); //remove the first space occurence and trim
$end = substr(strrchr($end,” “),1);//find the last word eg jumps
$end = $end.”.”.$name_end; //returns jumps.jpg

//Now get the page and find the image that ends in “jumps.jpg”

$str = file_get_contents(“http://site.com/”);
preg_match_all(‘/<img src=['"](.*?.(‘ . preg_quote($end, ‘~’) . ‘))['"]/’, $str, $a);

foreach ($a[1] as $c) {
echo $c;

break;
}

_________________________________________________

The problem is the preg match doesnt find the image ending in “jumps.jpg”


Preg_match_all Help

Categories: Programming Tags: , , , , , ,
Comments are closed.
Bear