Re: code quest

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ok, let's kick this around.

iterating an array(?; 1 dimensional listing of things) in php, I am creating a list of direcoties. I want to open and read in a file in each directory with a standard name, which contains a 1 line description of the directory and it's purpose.

Now, here's the existing code; this code is online NOW at this url:
http://www.howlermonkey.net/dirlisting.php

   * 1<?php # The next several lines declare an array of directories
which are 2NOT to be listed!
    3$excludes[] = 'images';
    4$excludes[] = 'cgi-bin';
    5$excludes[] = 'vti_cnf';
    6$excludes[] = 'private';
    7$excludes[] = 'thumbnail';
    8
    9$ls = scandir(dirname(__FILE__));
   10foreach ($ls as $d) {
   11if (is_dir($d) && !preg_match('/^\./',basename($d)) &&
   12!in_array(basename($d),$excludes)) {
   13     echo '<li><a href="'.$d.'">'.$d.'</a><br/>'.PHP_EOL;
   14 }
   15}
   16?>*

Let's say the file to read in /elite is named 'desc.txt'.
It looks like you want me to modify line 13 to say:
echo '<li><a href="'.$d.'">'.include($d.'desc.txt').'</a><br/>'.PHP_EOL;

so, if the file '/elite/desc.txt' contains the line

   *82nd Airbourne - We are an elite unit of army Paratroopers
   *

Then that element in the list would appear as:

   * 82nd Airbourne  -We are an elite unit of army Paratroopers

And would be clickable. Let's try it and see if this hound hunts.

Matt Graham wrote:
From: Kirk Bailey <kbailey@xxxxxxxxxxxxxxxx>
OK, now here's a giggle; I like ssi includes. If I put the script
in as an ssi include, will it still work?

If you're using Apache, and you do

<!--#include virtual="something.php" -->

...the PHP in something.php will execute and produce output, but
something.php will not have any access to $_GET or $_POST or $_SESSION or any
of those things.  This is generally not what you want.  If you do

<?php include("something.php"); ?>

...then something.php will be able to see and work with the superglobals that
have been set up further up the page, which is *usually* what you want.  You
could try both approaches in a test env and see what you get.  I'll use SSI
for "dumb" blocks of text and php include for "smart" blocks of code, because
IME that tends to produce fewer instances of gross stupidity.

Note that YMMV on all this and ICBW.


--
end

Very Truly yours,
                - Kirk Bailey,
                  Largo Florida

kniht +-----+ | BOX | +-----+ think

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux