lehula Posted July 14, 2007 Share Posted July 14, 2007 I'm retrieving all images in a section of my source code. I want it to skip all the images that have the id="blocker". I've tried using strpos to search for the id in the image src. I then try to skip the image with that id by using the 'continue' expression, but it's not working. Can someone help me out? Thanks. //retrieve all images within the above string preg_match_all('#<img\s[^>]*src\s*=\s*[\'"]?([^\'"\s>]+)[\'"]?[\s>]#i', $matches[0], $images); foreach($images[1] as $image) { $ider = 'id="blocker"'; $pos = strpos($image, $ider); if ($pos === true) { continue;} else { echo "document.getElementById('randompic".$h."').src=\"".$image."\";"; echo "document.getElementById(\"picaddress".$h."\").value = \"".$image."\";"; echo "document.getElementById('randompic".$h."').style.visibility = \"visible\";"; echo "document.getElementById(\"randomcheck".$h."\").checked = \"true\";"; echo "document.getElementById('randompreview".$h."').src=\"".$image."\";"; $h++;} } Link to comment https://forums.phpfreaks.com/topic/60004-retrieve-only-images-without-a-certain-id/ Share on other sites More sharing options...
ToonMariner Posted July 14, 2007 Share Posted July 14, 2007 try <?php preg_match_all('#<img(?!>)*?>#i', $matches[0], $images); foreach($images[1] as $image) { $ider = 'id="blocker"'; $pos = strpos($image, $ider); if ($pos !== false) { echo "document.getElementById('randompic".$h."').src=\"".$image."\";"; echo "document.getElementById(\"picaddress".$h."\").value = \"".$image."\";"; echo "document.getElementById('randompic".$h."').style.visibility = \"visible\";"; echo "document.getElementById(\"randomcheck".$h."\").checked = \"true\";"; echo "document.getElementById('randompreview".$h."').src=\"".$image."\";"; $h++;} } ?> Link to comment https://forums.phpfreaks.com/topic/60004-retrieve-only-images-without-a-certain-id/#findComment-298455 Share on other sites More sharing options...
lehula Posted July 15, 2007 Author Share Posted July 15, 2007 thanks for the help, but it's not retrieving any images with that. Ill keep trying. Link to comment https://forums.phpfreaks.com/topic/60004-retrieve-only-images-without-a-certain-id/#findComment-298513 Share on other sites More sharing options...
lehula Posted July 15, 2007 Author Share Posted July 15, 2007 I can't get it to work, any help from anyone would be great Link to comment https://forums.phpfreaks.com/topic/60004-retrieve-only-images-without-a-certain-id/#findComment-298524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.