Board index   FAQ   Search  
Register  Login
Board index PHP PHP General

Include all files in a dir.

General discussions related to php

Moderators: macek, egami, gesf

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.
Osiris
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sat Oct 05, 2002 2:33 pm

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!
Jay
 

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();
?>
Osiris
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sat Oct 05, 2002 2:33 pm

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!
Jay
 

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

i'm not confused, my code does exactly what I wanted.
Osiris
New php-forum User
New php-forum User
 
Posts: 3
Joined: Sat Oct 05, 2002 2:33 pm

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
Jay
 


Return to PHP General

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron