Re: [PHP] code quest
OK, now here's a giggle; I like ssi includes. If I put the script in as an ssi include, will it still work? The functionality would also be useful on a page besides the default landing page, such as a 404error.html page, or a thank you page. -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht +-+ | BOX | +-+ think -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] code quest
A good point, but in this application there WILL be AT LEAST 1 legitimate directory at all times, or else the script would not be used, so this ought not be a problem. My problem is that I understand the basic functions to implement, but have not yet aquired sufficient command of php to implement the required multi step algorithm. Jim Lucas wrote: On 11/26/2010 4:03 PM, Kirk Bailey wrote: Hello all, my name is Kirk Bailey, and I am new to php, so please be forbearing. I code in python, and am trying to learn this language as our new client runs a web business based in it. I need a routine that will return a list of every directory immediately under the current directory- but nothing else, just a list of directories, 1 level deep, NO FILES, no listing of current dir or prior dir either. Now in python, I would use os.walk, and use the list of dirs and throw the other 2 lists away, but this ain't Kansas anymore. Does php even DO lists? Um, a list is a 1 dimenional array, if have a list ALIST and you plug in 3, you get back the contents of cell 3 in the list, whaqtever that content is. so if cell 3 in a 6 celled list was "Ruby" then ALIST[3] would return the string "ruby". It's easy to iterate lists. For instance: print '' for dir in ALIST: print '",dir,' print ' This would let me produce an ordered list of directories, each a link to that directory. This way, when a client installs a new product, the home page area listing products offered automatically updates. Further embellishment would let me replace the dir name with a BRIEF description from a descriptor file read from that dir. Now how to do this in php? This should do. The only problem that I foresee would be an empty "" if you have no directories returned by glob(). print(''); foreach ( glob('./*', GLOB_ONLYDIR) AS $dir ) print(''.$dir.''); print(''); Jim Lucas -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht +-+ | BOX | +-+ think
Re: [PHP] code quest
Now Now, fight nice. We don need no stinkin' @$^*$^(! woids here. :-P Steve Staples wrote: On Thu, 2010-12-02 at 10:07 -0500, Daniel P. Brown wrote: On Wed, Dec 1, 2010 at 23:13, Kirk Bailey wrote: [snip!] Can this be improved to exclude anything with a '.' or a '-' in it's name? This will exclude the smileys and cgi-bin and such. If it can be persuaded to read a 1 line description from each subdirectory it could then use THAT as the text in the link, instead of the name. This could be useful in many settings. Sure. Change: if (is_dir($d) && $d != '.' && $d != '..') { To: if (is_dir($d) && !preg_match('/[\.\-]/',$d)) { Keep in mind, though, that the change will no longer show anything that matches the below either: example.directory example-directory special-images css.files In other words, you may instead want to explicitly state which directories to omit, and then drop anything that begins with a dot as well (hidden directories on *NIX-like boxes) like so: '.$d.''.PHP_EOL; } } ?> -- Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/ damn you Daniel... I was just about to reply with almost the EXACT same answer!!! I think the last example would probably be the best one to use, that way you can still have some directories with the . or - or even the _ in the names, and still be able to display them. Steve ps thanks for saving me type it all out Daniel :) -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht +-+ | BOX | +-+ think
Re: [PHP] code quest
my current code is as follows: * '.$d.''.PHP_EOL; } } ?> * The page containing this is at this url: http://www.howlermonkey.net/dirlisting.php I believe this will be a starting point for the functionality I am looking for- an automatic menu of areas in a website one may go to. By excluding some folders, people don't go trespassing into the cgi-bin or images folder, or into areas reserved for administrative uses. Daniel P. Brown wrote: On Wed, Dec 1, 2010 at 23:13, Kirk Bailey wrote: [snip!] Can this be improved to exclude anything with a '.' or a '-' in it's name? This will exclude the smileys and cgi-bin and such. If it can be persuaded to read a 1 line description from each subdirectory it could then use THAT as the text in the link, instead of the name. This could be useful in many settings. Sure. Change: if (is_dir($d) && $d != '.' && $d != '..') { To: if (is_dir($d) && !preg_match('/[\.\-]/',$d)) { Keep in mind, though, that the change will no longer show anything that matches the below either: example.directory example-directory special-images css.files In other words, you may instead want to explicitly state which directories to omit, and then drop anything that begins with a dot as well (hidden directories on *NIX-like boxes) like so: '.$d.''.PHP_EOL; } } ?> -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht +-+ | BOX | +-+ think
Re: [PHP] code quest
From: Kirk Bailey > 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 ...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 ...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. -- Matt G / Dances With Crows The Crow202 Blog: http://crow202.org/wordpress/ There is no Darkness in Eternity/But only Light too dim for us to see -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] code quest
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 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 ''.$d.''.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 ''.include($d.'desc.txt').''.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 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 ...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 ...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
Re: [PHP] code quest
The hound barks, but does not yet properly hunt, and we need to bring home the bacon. OK, here is the current code: '.include('./'.$d.'/desc.txt') ;#.''.PHP_EOL; } } ?> the url again, to view the results, is http://www.howlermonkey.net/dirlisting.php and is live right now. The results are a tad odd to say the least. Kirk Bailey wrote: 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'.$d.''.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 ''.include($d.'desc.txt').''.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 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 ...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 ...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
Re: [PHP] code quest
On Dec 4, 2010, at 2:15 PM, Kirk Bailey wrote: The hound barks, but does not yet properly hunt, and we need to bring home the bacon. OK, here is the current code: '.include('./'.$d.'/desc.txt') ;#.''.PHP_EOL; } } ?> the url again, to view the results, is http://www.howlermonkey.net/dirlisting.php and is live right now. The results are a tad odd to say the least. Ok, I don't think that's actually the code that generated the page you link to, but let's go with what you've got. First of all, include() does not return a string to the calling program. include() basically redirects the php interpretter to process the contents of the file. What include() returns is success or failure of the execution of the included script. To use the current setup you have with the desc.txt files, you want to do something like this: echo ''; include('./'.$d.'/desc.txt'); echo ''.PHP_EOL; If the file desc.txt contains only text, it will get sent to the browser as is. Kirk Bailey wrote: 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'.$d.''.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 ''.include($d.'desc.txt').'>'.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 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 ...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 ...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 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] code quest
the code is now: '; echo include($d.'/desc.txt' ); echo ''.PHP_EOL; } } ?> And it works! BUT! Where is the "1" coming from?!? Please inspect the page and see what I mean. This is not in the code, and it's not in the source file. Link: http://www.howlermonkey.net/dirlisting.php I hope this dialog is proving at least mildly interesting to the remainder of the list as an educational exercise. Tamara Temple wrote: On Dec 4, 2010, at 2:15 PM, Kirk Bailey wrote: The hound barks, but does not yet properly hunt, and we need to bring home the bacon. OK, here is the current code: '.include('./'.$d.'/desc.txt') ;#.''.PHP_EOL; } } ?> the url again, to view the results, is http://www.howlermonkey.net/dirlisting.php and is live right now. The results are a tad odd to say the least. Ok, I don't think that's actually the code that generated the page you link to, but let's go with what you've got. First of all, include() does not return a string to the calling program. include() basically redirects the php interpretter to process the contents of the file. What include() returns is success or failure of the execution of the included script. To use the current setup you have with the desc.txt files, you want to do something like this: echo ''; include('./'.$d.'/desc.txt'); echo ''.PHP_EOL; If the file desc.txt contains only text, it will get sent to the browser as is. Kirk Bailey wrote: 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'.$d.''.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 'href="'.$d.'">'.include($d.'desc.txt').''.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 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 ...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 ...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 -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht +-+ | BOX | +-+ think
Re: [PHP] code quest
On 4 December 2010 20:58, Kirk Bailey wrote: > the code is now: > > are NOT to be listed! > $excludes[] = 'images'; > $excludes[] = 'cgi-bin'; > $excludes[] = 'vti_cnf'; > $excludes[] = 'private'; > $excludes[] = 'thumbnail'; > > $ls = scandir(dirname(__FILE__)); > foreach ($ls as $d) { > if (is_dir($d) && !preg_match('/^\./',basename($d)) && > !in_array(basename($d),$excludes)) { > echo ''; > echo include($d.'/desc.txt' ); > echo ''.PHP_EOL; > } > } > ?> > > And it works! > BUT! > Where is the "1" coming from?!? > Please inspect the page and see what I mean. This is not in the code, and > it's not in the source file. Link: > http://www.howlermonkey.net/dirlisting.php > > I hope this dialog is proving at least mildly interesting to the remainder > of the list as an educational exercise. > > > Tamara Temple wrote: >> >> On Dec 4, 2010, at 2:15 PM, Kirk Bailey wrote: >> >>> The hound barks, but does not yet properly hunt, and we need to bring >>> home the bacon. >>> >>> OK, here is the current code: >>> >>> >> are NOT to be listed! >>> $excludes[] = 'images'; >>> $excludes[] = 'cgi-bin'; >>> $excludes[] = 'vti_cnf'; >>> $excludes[] = 'private'; >>> $excludes[] = 'thumbnail'; >>> >>> $ls = scandir(dirname(__FILE__)); >>> foreach ($ls as $d) { >>> if (is_dir($d) && !preg_match('/^\./',basename($d)) && >>> !in_array(basename($d),$excludes)) { >>> echo ''.include('./'.$d.'/desc.txt') >>> ;#.''.PHP_EOL; >>> } >>> } >>> ?> >>> >>> the url again, to view the results, is >>> http://www.howlermonkey.net/dirlisting.php and is live right now. The >>> results are a tad odd to say the least. >>> >> >> Ok, I don't think that's actually the code that generated the page you >> link to, but let's go with what you've got. >> >> First of all, include() does not return a string to the calling program. >> include() basically redirects the php interpretter to process the contents >> of the file. What include() returns is success or failure of the execution >> of the included script. To use the current setup you have with the desc.txt >> files, you want to do something like this: >> >> echo ''; >> include('./'.$d.'/desc.txt'); >> echo ''.PHP_EOL; >> >> If the file desc.txt contains only text, it will get sent to the browser >> as is. >> >> >>> >>> >>> >>> Kirk Bailey wrote: 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>>> 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 ''.$d.''.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 ''.include($d.'desc.txt').''.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 > >> 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 > > > > ...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 > > > > ...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 +-+
Re: [PHP] code quest
On Sat, Dec 4, 2010 at 15:58, Kirk Bailey wrote: > > And it works! > BUT! > Where is the "1" coming from?!? No need to see the page. You're echo'ing an include. No need to do that; including the file is enough, and that's what's working. Adding the echo makes it print the status returned by 'include' --- which is boolean TRUE, AKA 1. -- Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] code quest
On Dec 4, 2010, at 2:58 PM, Kirk Bailey wrote: the code is now: '; echo include($d.'/desc.txt' ); There should be no echo here echo ''.PHP_EOL; } } ?> And it works! BUT! Where is the "1" coming from?!? Please inspect the page and see what I mean. This is not in the code, and it's not in the source file. Link: http://www.howlermonkey.net/dirlisting.php I hope this dialog is proving at least mildly interesting to the remainder of the list as an educational exercise. Tamara Temple wrote: On Dec 4, 2010, at 2:15 PM, Kirk Bailey wrote: The hound barks, but does not yet properly hunt, and we need to bring home the bacon. OK, here is the current code: which are NOT to be listed! $excludes[] = 'images'; $excludes[] = 'cgi-bin'; $excludes[] = 'vti_cnf'; $excludes[] = 'private'; $excludes[] = 'thumbnail'; $ls = scandir(dirname(__FILE__)); foreach ($ls as $d) { if (is_dir($d) && !preg_match('/^\./',basename($d)) && !in_array(basename($d),$excludes)) { echo ''.include('./'.$d.'/desc.txt') ;#.''.PHP_EOL; } } ?> the url again, to view the results, is http://www.howlermonkey.net/dirlisting.php and is live right now. The results are a tad odd to say the least. Ok, I don't think that's actually the code that generated the page you link to, but let's go with what you've got. First of all, include() does not return a string to the calling program. include() basically redirects the php interpretter to process the contents of the file. What include() returns is success or failure of the execution of the included script. To use the current setup you have with the desc.txt files, you want to do something like this: echo ''; include('./'.$d.'/desc.txt'); echo ''.PHP_EOL; If the file desc.txt contains only text, it will get sent to the browser as is. Kirk Bailey wrote: 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'.$d.''.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 ''.include($d.'desc.txt').'>'.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 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 ...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 ...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 -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht+- + | BOX | +- +think -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php