Jump to content

retrieve only images without a certain id.


lehula

Recommended Posts

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++;}

}

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++;}
}
?>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.