Michael, I wrote this function for a project that I'm working on. It
returns an indexed array of local links found on a given page. It returns
false if the url is not a valid file. If you want it to return all links
regardless of prefix or file extension then just return $arrayoflinks[1]
instead of doing the extra ereg() steps. It's a very simple function, but
it may help get you started.
-Kevin
function extract_links($url)
{
$fp = fopen($url, "r"); // fopen to check for valid file
if ($fp !== false)
{
fclose($fp);
$contents = implode("", file($url));
// Much thanks to whomever wrote this regex!
preg_match_all("|href=\"?([^\"' >]+)|i", $contents, $arrayoflinks);
foreach ($arrayoflinks[1] as $link)
{
// Ignore links that may not be local.
if (!ereg('http://', $link))
{
// Make sure the link is some form of html file.
if (ereg('.htm', $link))
{
// Build array of local links on this page.
$links[] = $link;
}
}
}
return $links;
}
else
{
return false;
}
}
----- Original Message -----
From: "_michael" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, May 24, 2002 12:12 PM
Subject: RE: [PHP] listing the files in the directory
> well do you think you can point me in the right direction to listing the
> files on my site? - is it possible (as i said i am very new to this)
>
> thanks
>
> -----Original Message-----
> From: Jason Wong [mailto:[EMAIL PROTECTED]]
> Sent: 24 May 2002 19:09
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] listing the files in the directory
>
>
> On Saturday 25 May 2002 02:01, _michael wrote:
> > hi, i'm pretty new to php - i am trying to list/print a list of files
and
> > folders that are on my server:
> >
> > from my little knowledge i have got:
> >
> > <?php
> > $dir = "http://mysite.com/";
> > $handle = opendir($dir);
> > while (($file = readdir($handle))) {
> > if ($file != "." && $file != "..") {
> > echo "- " . $file . "<br>";
> > }
> > }
> > ?>
> >
> > i keep getting errors - will this code list the files on my site?
>
> No. You can only opendir() a local filesystem.
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
>
> /*
> It's clever, but is it art?
> */
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php