Jump to content

How to read contents of a remote directory


JoeF

Recommended Posts

Hey guys,

Im working on a spider/crawler for a specialist search engine. Im trying to get my script to load the contents of a directory into a variable. Similar to how you woud use:

[code]$html = implode('', file($url)) ;[/code]
to load html of a remote page into a variable.

However when $url is a directory eg: http://www.vobe.frihost.net/testing/

You can go to view source in your browser and see the html, but it just hangs when using file() to view it, obviously cos its not a file.
Im guessing the browser is generating the html for that directory.

What i need to know is how to let php get that html so i can pharse the links out of the directory.


Thanks
Hope someone can help!
Link to comment
Share on other sites

Even when you are looking at a directory listing like that, it's still HTML.  So you will need to take the html, then search for links to files.  Someone who's better with regex can help with that.

What I can tell you is that there is a better way to get the html than you are using:

[code]$remote_html = file_get_contents("http://www.vobe.frihost.net/testing/");[/code]

Alternatly use sockets, there are some good examples on the fsockopen manual page:

http://www.php.net/fsockopen
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.