Get url list

Discussion in 'PHP' started by csdname, Feb 17, 2010.

  1. #1
    Hi.
    Hi have one page having some code like this:
    <html>
    <body>
    <a href="url1">tex 1</a>
    <a href="url2">tex 2</a>
    <a href="url3">tex 3</a>
    ...
    </body>
    </html>
    Code (markup):
    I want to print in other page the the url list in that page between the <body> </body> tags.

    Something like:

    Url list in your homepage:
    url1
    url2
    url3
    ...


    Please help me with this.

    Thanks.
     
    csdname, Feb 17, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    <?php
    
    //the page...
    $page = "http://en.wikipedia.org/wiki/Benchmark";
    
    preg_match("/<body[^>]*>(.*?)<\/body>/is", file_get_contents($page), $matches);
    
    $body = $matches[1];
    
    preg_match_all('/<(a.*) href="(.*?)"(.*)>/', $body, $matches); 
    
    foreach($matches[2] as $match){
    
    echo $match."<br>";
    }
    
    ?>
    PHP:
     
    Last edited: Feb 17, 2010
    danx10, Feb 17, 2010 IP
  3. csdname

    csdname Well-Known Member

    Messages:
    144
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    131
    #3
    Thank you. ;)
     
    csdname, Feb 18, 2010 IP