...

View Full Version : Finding images w/ preg_match_all Problem



chinesedom
02-22-2012, 11:25 AM
Hey folks,

I use a plugin for wordpress called Image Voting from Flaunt books (http://www.flauntbooks.com/wordpress-plugins/image-voting-plugin.html).

The script does find ordinary images just like these:

<img src="http://www.traumhafte-abendkleider.de/wp-content/themes/peaceful-rush_1/images/abendkleider_abendkleid_logo01.jpg" alt="Traumhafte-Abendkleider" />


But it doesnt work with images like these:

<div id="ngg-image-160" class="ngg-gallery-thumbnail-box" >
<div class="ngg-gallery-thumbnail" >
<a href="http://www.traumhafte-abendkleider.de/wp-content/gallery/rubensengel_kinderkleider/kleid-blumenkind-mintgruen.jpg" title=" " >
<img title="Blumenkind Kleid mintgruen" alt="Blumenkind Kleid mintgruen" src="http://www.traumhafte-abendkleider.de/wp-content/gallery/rubensengel_kinderkleider/thumbs/thumbs_kleid-blumenkind-mintgruen.jpg" width="400" height="600" />
</a>
</div>
</div>


I checked the code for quite a while and think the problem might be somewhere with the preg_match_all or contents of $pattern1 / $pattern2.



What can I do to find all images???



This is the code to find the images:

function _find_images( $content )
{
$pattern1 = "/<(a[^>]*)><(img[^>]*)><\/a>/i";
$pattern2 = "#<img(.*)src=(.*)>#i";

preg_match_all( $pattern1, $content, $res1 );
preg_match_all( $pattern2, $content, $res2 );


$tmppics = array();

foreach($res1[0] as $html){
if($fb['imagevote_debug']){ echo 'res='.$res; } // debug by dom
$pos = strpos($html, "novote"); // if class = novote don't add voting
// kommentiert von dominik $pos2 = strpos($html, "gallery-holder"); // p3 flash & lightbox galleries
$pos2 = false;
// $pos = strpos($html, "attachment-thumbnail"); // if class = attachment-thumbnail
if ($pos === false && $pos2 === false) {
$tmppics[] = ImageVote::_parse_image( $html );
echo $pos . '=pos ; pos2 = '. $pos2; // debug von dom
}
}

foreach($res2[0] as $html){
if($fb['imagevote_debug']){ echo 'res2='.$res2; } // debug by dominik
$pos = strpos($html, "novote"); // if class = novote don't add voting
// kommentiert von dominik $pos2 = strpos($html, "gallery-holder"); // p3 flash & lightbox galleries
$pos2 = false;
// $pos = strpos($html, "attachment-thumbnail"); // if class = attachment-thumbnail
if ($pos === false && $pos2 === false) {
$tmppics[] = ImageVote::_parse_image( $html );
echo $pos . '=pos ; pos2 = '. $pos2; // debug von dom
}
}

$links = array();
$pics = array();
foreach($tmppics as $pic)
if($pic['src'])
if(!$links[$pic['src']])
{
$links[$pic['src']] = 1;
$pics[] = $pic;
}
echo 'DEBUG->PICCOUNT2:'.count($pics);
return $pics;
}

KuriosJon
02-22-2012, 01:43 PM
I didn't take a real close look at your code, but $pattern2 should find all images if used correctly: See example (http://regexpal.com/?flags=i&regex=%3Cimg(.*)src%3D(.*)%3E&input=%3Cdiv%20id%3D%22ngg-image-160%22%20class%3D%22ngg-gallery-thumbnail-box%22%20%20%3E%0A%3Cdiv%20class%3D%22ngg-gallery-thumbnail%22%20%3E%0A%3Ca%20href%3D%22http%3A%2F%2Fwww.traumhafte-abendkleider.de%2Fwp-content%2Fgallery%2Frubensengel_kinderkleider%2Fkleid-blumenkind-mintgruen.jpg%22%20title%3D%22%20%22%20%20%3E%0A%3Cimg%20title%3D%22Blumenkind%20Kleid%20mintgruen%2 2%20alt%3D%22Blumenkind%20Kleid%20mintgruen%22%20src%3D%22http%3A%2F%2Fwww.traumhafte-abendkleider.de%2Fwp-content%2Fgallery%2Frubensengel_kinderkleider%2Fthumbs%2Fthumbs_kleid-blumenkind-mintgruen.jpg%22%20width%3D%22400%22%20height%3D%22600%22%20%2F%3E%0A%3C%2Fa%3E%0A%3C%2Fdiv%3E%0A%3C %2Fdiv%3E%0A%3Cimg%20src%3D%22http%3A%2F%2Fwww.traumhafte-abendkleider.de%2Fwp-content%2Fthemes%2Fpeaceful-rush_1%2Fimages%2Fabendkleider_abendkleid_logo01.jpg%22%20alt%3D%22Traumhafte-Abendkleider%22%20%2F%3E%0A)

chinesedom
02-22-2012, 05:46 PM
Thanks Jon,

now i know the problem isnt the function itself...

Its here: The Content still has unprocessed content from NextGenGallery. This is what I get:


[nggallery id=6]
Instead of all the pictures...

How can i get the html code from the whole post??



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum