Why can not I display the picture?

Discussion in 'PHP' started by fixesign, Apr 30, 2011.

  1. #1
    At most sites, can work well when using the code below:
    <?php
    include "simple_html_dom.php";
    $url = $_POST[url];
    $html = file_get_html($url);  
       
     foreach($html->find('img') as $element)  
            echo '<img src='.$element->src.'><br>';
    ?>
    PHP:
    But for some sites, I do not get the "src" with the correct url. For example:
    $ url = http://www.example.com
    and/or
    $ url = http://www.example.com/article/detail-of-article.html
    I can not display the image because in the "src" I just get a format like this:
    images/photo-1.jpg
    images/photo-2.jpg
    images/photo-3.jpg

    and/or
    ../images/photo-1.jpg
    ../images/photo-2.jpg
    ../images/photo-3.jpg

    Help me, friends...
     
    fixesign, Apr 30, 2011 IP
  2. lioncub5

    lioncub5 Peon

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The dom is working fine. It's just the way some websites are written.
    When making internal links to pages and directories on the same domain, certain web authors use relative filepaths instead of the full httpwww...
    You need to check each of the links to see whether or not its a valid url, and prepend the domain name and any directories in place of "../"
     
    lioncub5, Apr 30, 2011 IP
  3. fixesign

    fixesign Member

    Messages:
    175
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #3
    How to do that? Help me, friends...
     
    fixesign, Apr 30, 2011 IP
  4. fixesign

    fixesign Member

    Messages:
    175
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    28
    #4
    Hi.
    Is there a friend who can help me, how to make the code for the above problem? please help me... thanks in advance...
     
    fixesign, May 3, 2011 IP
  5. careerfield

    careerfield Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    try adding

    <?php
    include "simple_html_dom.php";
    $url = $_POST; $html = file_get_html($url); ...site.com/images/'.$element->src.'\"><br>'; ?>
     
    careerfield, May 5, 2011 IP