Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Finding images w/ preg_match_all Problem

    Hey folks,

    I use a plugin for wordpress called Image Voting from Flaunt books.

    The script does find ordinary images just like these:
    Code:
    <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:
    Code:
    <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:
    PHP Code:
    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;
      } 

  • #2
    Regular Coder
    Join Date
    Jan 2012
    Posts
    134
    Thanks
    0
    Thanked 32 Times in 32 Posts
    I didn't take a real close look at your code, but $pattern2 should find all images if used correctly: See example

  • #3
    New to the CF scene
    Join Date
    Feb 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

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

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •