www.webdeveloper.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 41

Thread: Link checker

Hybrid View

  1. #1
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413

    Link checker

    Hey, guys, I've got yet another question. I was thinking today, and wondering... How would I use PHP to go to a page and follow all of the links on that page and print their URIs? Any ideas? I haven't come up with anything, but I am definitely ready and willing to learn this new field.

    Thanks,

    Jona
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  2. #2
    Join Date
    Feb 2003
    Location
    Britain
    Posts
    1,335
    Is it possible to open pages outside your own server with PHP? I only know about fopen, and that is your-server only.

  3. #3
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    So do I, but it must be possible. I mean, unless you have to use CGI, but PHP should be able to do it, too.

    http://validator.w3.org/ searches through the source of a specific URI (or an uploaded temporary file, but I know how to do that).

    There is another site that checks spelling, links, etc., etc. on a Web page you specify. How do I make PHP follow links from page to page and write out the results (example: visit somesite.com, find all of the links on the page, print them all out, go to each one of those pages individually and print them out, etc.).

    That's what I meant.... lol
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  4. #4
    Join Date
    Feb 2003
    Location
    Britain
    Posts
    1,335
    I know how you can get it to find links, but if I can't make it open pages, it isn't much use, really. Where's Pyro...

  5. #5
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    He's, "not at my desk" right now... Man, he would know... (lol)

    While we wait, though, how's about you show me some PHP code about getting all the links on a page? (I could just use Javascript and frames.... lol, but I don't wanna do that..)
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  6. #6
    Join Date
    Feb 2003
    Location
    Britain
    Posts
    1,335
    validator.w3.org is using PHP. Now if they'd just written how they did it...

  7. #7
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  8. #8
    Join Date
    Feb 2003
    Location
    Britain
    Posts
    1,335
    How strange, if you try to go to it by using index.php in their chck directory, it finds it.

    This PHP regular expression should find any and all hyperlinks and return them. You would just need to loop. (Soz, I haven't tested it. I'm not at home, I'm on a laptop with a dial up.)

    PHP Code:
    $look=ereg(<[a-zA-Z0-9]* href="[a-zA-Z0-9]*" [a-zA-Z0-9]*>[a-zA-Z0-9]*</a>); 

  9. #9
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Hmmm.... I see. That looks interesting. It looks like one of the most used things in PHP is RegExps... I'll have to study more on those. lol
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  10. #10
    Join Date
    Feb 2003
    Location
    Britain
    Posts
    1,335
    I've been using PHP for a while, and they are quite hard to use. Most often they can be replaced by simpler code, so I don't use them enough to become good.

  11. #11
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    I see. Well, I'll get good at 'em nonetheless! lol
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  12. #12
    Join Date
    Nov 2002
    Location
    Dartmoor [Holiday]
    Posts
    2,382
    You should be able to open the links with CURL.

    Adam
    "If you’re not using valid HTML, then you haven’t created a Web page. You may have created something else, but it isn’t a Web page." - Joe Clark

    Do something amazing (USA) | Make Poverty History

  13. #13
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Adam, I'm assuming I'll need to install the package on my server then, right? I don't think I can do that on a free server... Is there any other way possible? (I will check to see if it's already installed on my server, which hopefully it is.)
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

  14. #14
    Join Date
    Dec 2002
    Location
    High on life
    Posts
    10,104
    Is this what you are looking for, Jona?

    PHP Code:
    <?php

    $code 
    file ('http://www.yahoo.com/'); // file to open

    foreach ($code as $line_num => $line) { // loop through lines
        
    echo "<span style=\"font-weight:bold;\">Line #$line_num :</span> " htmlspecialchars($line) . "<br>\n"// echo lines to screen. Note htmlspecialchars() convers special characters to their HTML entities
    }
    ?>

    Personal website http://www.ryanbrill.com/
    Business website: http://www.infinitywebdesign.com/
    TypeSpace http://www.typespace.org/

    I reject your reality and substitute it with my own!

  15. #15
    Join Date
    Jan 2003
    Location
    Texas
    Posts
    10,413
    Cijori, two things. One: Your code doesn't work. Two, I changed it up to make it work, but when I do it prints nothing. How can I fix this?

    Thanks.
    Visit Slightly Remarkable to see my portfolio, resumé, and consulting rates.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles