SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    29
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    please help - showing all images from an URL

    i have a code ive been working on

    its supposed to grab all images from a posted URL that are larger than 80x80 and put them into an array

    but its not working properly, it works for most web sites, but not all of them

    heres the code:

    PHP Code:
      if (substr($url, -1) != '/')
        
    $ddurl "$url/";
      else
        
    $ddurl $url;
      
      
    $ddcontent file_get_contents($ddurl);
      
      
    preg_match_all('/<img.*src="(.*?)".*?>/i'$ddcontent$ddmatches);
      
      foreach (
    array_unique($ddmatches[1]) as $ddimg)
      {
        if (
    $ddimg[0] == '/')
          
    $ddimg substr($ddimg1);
      
        if (!
    preg_match("/^http/i"$ddimg))
          
    $ddimg "$ddurl$ddimg";

        
    $ddmysock getimagesize($ddimg);
        
    $ddwidth $ddmysock[0];
        
    $ddheight $ddmysock[1];
        
        if (
    $ddwidth 80 && $ddheight 80)
        {
          if (
    $ddwidth 150 || $ddheight 150)
          {
            if (
    $ddwidth $hddeight)
              
    $ddpercentage = (150 $ddwidth); 
            else
              
    $ddpercentage = (150 $ddheight);
              
            
    $ddwidth round($ddwidth $ddpercentage); 
            
    $ddheight round($ddheight $ddpercentage); 
          }

          
    $ddimgtag "<img src=\"$ddimg\" width=\"$ddwidth\" height=\"$ddheight\">";
          
          
    $newimages[] = array('url' => $ddimg'img_tag' => $ddimgtag);
        }
      } 

  2. #2
    SitePoint Addict
    Join Date
    Jul 2008
    Location
    sudo rm -rf /
    Posts
    386
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try replacing this:
    preg_match_all('/<img.*src="(.*?)".*?>/i', $ddcontent, $ddmatches);
    with
    preg_match_all('/<[\s]?img[\s]?[^\/>]+[\s]?src="([^\"]+)"[\s]?[^\/>]+[\s]?[\/]?>/i', $ddcontent, $ddmatches);


Bookmarks

Posting Permissions

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