php web image search question

Discussion in 'PHP' started by youlichika, Apr 1, 2011.

  1. #1
    I want to do a picture search engine. I use `simple_html_dom` and `preg_match_all` to get all the image, then use `getimagesize` get all the image size.
    Here is one part of my code.

    <?php
    header('Content-type:text/html; charset=utf-8');
    require_once 'simple_html_dom.php';
    $v = 'http://www.jqueryimage.com/';
    $html = file_get_html($v);
    foreach($html->find('img') as $element) {
            if( preg_match('#^http:\/\/(.*)\.(jpg|gif|png)$#i',$element->src)){
                $image = $element->src;
                //$arr = getimagesize($image); //get image width and height
                //$imagesize = $arr[0] * $arr[1]; 
                echo $image.'<hr />';
            }
        }
    ?>
    PHP:
    First qusetion, how to add a judgement so that I can echo the biggest size image? (only one image).

    Second question, I can get the image real url in these two possibilities, first where image is as a 'http' began, second where image is as a '/' began.
    But how to get the image real url in the situation where image is as a './' or '../' or '../../' began? it is difficulty for me to judge how many '../' in a image, then cut the site url to complement a image real url?

    Maybe some one is good at php regular expressions or have good idea willing to help me. Thanks.
     
    youlichika, Apr 1, 2011 IP
  2. AlC4Tr4z

    AlC4Tr4z Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #2
    you can save all dimension in an array and use the max function to discover the biggest, keep in mind an image has x and y dimension, you can use max for one of those dimension, or u have to do a function that calculate the maximum based on sum of the x+y or something like that )

    Have a look at realpath function:
    http://it.php.net/realpath
     
    AlC4Tr4z, Apr 1, 2011 IP