Thanks. However, in this case the height can have a decimal place. (eg. 34.21) Yes, I know that's weird! I'm not sure if this is a regex problem so much as my looping perhaps not working correctly. My basic aim is to find a code which is on the page which is unique to each image. (eg. SP3 is relevant to image PRP1231231.jpg) I then need to find each instance of an image and add a button underneath the the image in which the href contains the unique code. What I have at the moment is:
Code: Select all
//gets the unique code
preg_match_all('#(["\'])'.preg_quote('http://www.domainname.com/cgi-bin/operate.pl?&prp1&&','#').'(.*?)\\1#',$result,$matches);
//gets the image name. $agentcode is a global variable set earlier on
preg_match_all ('/'.$agentcode.'\/images_p\/*([0-9a-zA-Z]{10})*.jpg/Uis', $result, $imagematch);
//now loop through each instance of an image, and add the button underneath it
$j=0;
for ($i=0; $i<count($imagematch[0]); $i++)
{
$result = preg_replace('/'.$imagematch[1][$i].'.jpg" border="1" width="120" height="([^\]]+)" alt="View"><\/a>/i', $imagematch[1][$i].'.jpg" border="1" width="120" height="\\1" alt="View"></a><br>'.$imagematch[1][$i].'<br><a href="arrange-viewing.php?pid='.$matches[2][$j].'"><img src="/images/arrange-viewing.gif" width="118" height="25" border="0"></a>', $result);
// there are two instances of the unique code on the page, so you have to skip through the array in twos
$j=$j+2;
}
This is partly working. What is happening though, is that the correct number of buttons are being added with the correct href, but only after the last instance of the image. So say there are three images and three unique codes, the above will reproduce the three images, and after the last of these, three buttons will appear. But there should be one button per image. It's confusing me severly, and I've echoed my variables out in the loop to see if I can spot it, but it's illuding me so far.
Any comments would be very welcome. Let me know if I'd be better putting this in the main PHP forum though.