Include all files in a dir.

General discussions related to php

Moderators: macek, egami, gesf

Osiris
New php-forum User
New php-forum User
Posts: 3
Joined: Sat Oct 05, 2002 2:33 pm
Contact:

Include all files in a dir.

Postby Osiris » Sat Oct 05, 2002 2:34 pm

I'd like to include the text of all html files in a directory, seperated by an hr.

Jay

Postby Jay » Sun Oct 06, 2002 9:49 am

Look up the file system functions. Learn how to read a directly for all the files, open the file, read it and print it, and then close each file in turn!

Osiris
New php-forum User
New php-forum User
Posts: 3
Joined: Sat Oct 05, 2002 2:33 pm
Contact:

Postby Osiris » Sun Oct 06, 2002 9:56 am

ya, here's my final code:

Code: Select all

<?
$d = dir("./");
while (false !== ($entry = $d->read())) {
   if(substr($entry,-4)=="html") {
   print "<hr>\n";

   include($entry);
   }
//   print $entry."\n";
}
$d->close();
?>

Jay

Postby Jay » Sun Oct 06, 2002 10:15 am

Errm, I think you're confused about classes!

Try something like this:

Code: Select all

$dir = "./";
while($file = each($dir)) {
if (substr($file,-4) == "html") print "<hr>\n".htmlspecialchars(file($file));
}

I just made that up, you might have to play with it a bit to get it to work!

Osiris
New php-forum User
New php-forum User
Posts: 3
Joined: Sat Oct 05, 2002 2:33 pm
Contact:

Postby Osiris » Sun Oct 06, 2002 10:16 am

i'm not confused, my code does exactly what I wanted.

Jay

Postby Jay » Sun Oct 06, 2002 10:41 am

Ok, my mistake, but if you knew the code, why did you bother asking?

As it's been sorted, I'll close this thread


Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 2 guests