[PHP] Re:[PHP] code quest
Frankly, while that modulo looks like something worthy of learning, for my immediate time critical need I went with a quicker method, which is working. The complete script is below. It simply counts cells and resets the row when a number is exceeded. ?php # The next several lines declare an array of directories which are NOT to be listed!# $excludes[] = 'attachments'; #20 $excludes[] = 'data'; $excludes[] = 'include'; $excludes[] = 'resources'; $excludes[] = 'stats'; $excludes[] = '_private'; $excludes[] = '_vti_bin'; $excludes[] = '_vti_cnf'; $excludes[] = '_vti_log'; $excludes[] = '_vti_pvt'; $excludes[] = '_vti_txt'; #30 $excludes[] = '_vxi_txt'; $excludes[] = 'css'; $excludes[] = 'img'; $excludes[] = 'images'; $excludes[] = 'js'; $excludes[] = 'cgi'; $excludes[] = 'cgi-bin'; $excludes[] = 'ssfm'; $ls = scandir(dirname(__FILE__)); $counter=0; #40 echo 'table border=1 cellspacing=1 cellpadding=5 bgcolor=F0F0F0tr'; foreach ($ls as $d) { if (is_dir($d) !preg_match('/^\./',basename($d)) !in_array(basename($d),$excludes)) { ++$counter ; echo 'td width=150 valign=topcenter'.$d.'bra href='.$d.''; echo 'img src=./'.$d.'/thumb.png width=120 HEIGHT=175 border=5/abr/center'; include($d./desc.txt); echo '/td'; if ($counter 3) { echo '/trtr'; #50 $counter=0; } }; }; echo '/tr/table'; ? -- 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
On 15 February 2011 00:53, Kirk Bailey kbai...@howlermonkey.net wrote: Now I have a situation. I need to take the code from my former home page and modify it to lay out a table (let's say 5 cells wide) and as many rows deep to contain all the items. Each item is the name of the directory, under which is an icon image from that directory, under which is a description file read from that directory. Here is my code thus far: ?php # The next several lines declare an array of directories which are NOT to be listed!# $excludes[] = 'attachments'; #20 $excludes[] = 'data'; $excludes[] = 'include'; $excludes[] = 'resources'; $excludes[] = 'stats'; $excludes[] = '_private'; $excludes[] = '_vti_bin'; $excludes[] = '_vti_cnf'; $excludes[] = '_vti_log'; $excludes[] = '_vti_pvt'; $excludes[] = '_vti_txt'; #30 $excludes[] = '_vxi_txt'; $excludes[] = 'css'; $excludes[] = 'img'; $excludes[] = 'images'; $excludes[] = 'js'; $excludes[] = 'cgi'; $excludes[] = 'cgi-bin'; $excludes[] = 'ssfm'; $ls = scandir(dirname(__FILE__)); echo 'table border=1 cellspacing=5 cellpadding=0 bgcolor=E0E0E0tr align=center'; #40 foreach ($ls as $d) { if (is_dir($d) !preg_match('/^\./',basename($d)) !in_array(basename($d),$excludes)) { echo 'td'.$d.'bra href='.$d.'img src=/Categories/'.$d.'/thumb.png border=5/abr'; include($d./desc.txt); echo '/td'; }; }; echo '/tr/table'; ? Now I am stymied on changing this to add /trtr at the right points in the structure. I am new to php, and welcome all suggestions and gainful comments. $ls = scandir(dirname(__FILE__)); echo 'table border=1 cellspacing=5 cellpadding=0 bgcolor=E0E0E0'; #40 foreach ($ls as $d) { if (is_dir($d) !preg_match('/^\./',basename($d)) !in_array(basename($d),$excludes)) { echo 'tr align=centertd', $d, 'bra href=', $d, 'img src=/Categories/', $d, '/thumb.png border=5/abr'; include($d./desc.txt); echo '/td/tr'; }; }; echo '/table'; maybe? -- Richard Quadling Twitter : EE : Zend @RQuadling : e-e.com/M_248814.html : bit.ly/9O8vFY -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] code quest
well, this ends the row after every cell. I am trying to get a row of 5 cells across, then end it and start a new row. If the routines stops before the end of the count of 5 due to lack of further directories, closing out the table following the loops will onclude a /tr tag. On 2/14/2011 8:30 PM, Richard Quadling wrote: On 15 February 2011 00:53, Kirk Baileykbai...@howlermonkey.net wrote: Now I have a situation. I need to take the code from my former home page and modify it to lay out a table (let's say 5 cells wide) and as many rows deep to contain all the items. Each item is the name of the directory, under which is an icon image from that directory, under which is a description file read from that directory. Here is my code thus far: ?php # The next several lines declare an array of directories which are NOT to be listed!# $excludes[] = 'attachments'; #20 $excludes[] = 'data'; $excludes[] = 'include'; $excludes[] = 'resources'; $excludes[] = 'stats'; $excludes[] = '_private'; $excludes[] = '_vti_bin'; $excludes[] = '_vti_cnf'; $excludes[] = '_vti_log'; $excludes[] = '_vti_pvt'; $excludes[] = '_vti_txt'; #30 $excludes[] = '_vxi_txt'; $excludes[] = 'css'; $excludes[] = 'img'; $excludes[] = 'images'; $excludes[] = 'js'; $excludes[] = 'cgi'; $excludes[] = 'cgi-bin'; $excludes[] = 'ssfm'; $ls = scandir(dirname(__FILE__)); echo 'table border=1 cellspacing=5 cellpadding=0 bgcolor=E0E0E0tr align=center'; #40 foreach ($ls as $d) { if (is_dir($d) !preg_match('/^\./',basename($d)) !in_array(basename($d),$excludes)) { echo 'td'.$d.'bra href='.$d.'img src=/Categories/'.$d.'/thumb.png border=5/abr'; include($d./desc.txt); echo '/td'; }; }; echo '/tr/table'; ? Now I am stymied on changing this to add/trtr at the right points in the structure. I am new to php, and welcome all suggestions and gainful comments. $ls = scandir(dirname(__FILE__)); echo 'table border=1 cellspacing=5 cellpadding=0 bgcolor=E0E0E0'; #40 foreach ($ls as $d) { if (is_dir($d) !preg_match('/^\./',basename($d))!in_array(basename($d),$excludes)) { echo 'tr align=centertd', $d,'bra href=', $d, 'img src=/Categories/', $d, '/thumb.png border=5/abr'; include($d./desc.txt); echo '/td/tr'; }; }; echo '/table'; maybe? -- 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
On 2/14/2011 4:53 PM, Kirk Bailey wrote: Now I have a situation. I need to take the code from my former home page and modify it to lay out a table (let's say 5 cells wide) and as many rows deep to contain all the items. Each item is the name of the directory, under which is an icon image from that directory, under which is a description file read from that directory. Here is my code thus far: ?php # The next several lines declare an array of directories which are NOT to be listed!# $excludes[] = 'attachments'; #20 $excludes[] = 'data'; $excludes[] = 'include'; $excludes[] = 'resources'; $excludes[] = 'stats'; $excludes[] = '_private'; $excludes[] = '_vti_bin'; $excludes[] = '_vti_cnf'; $excludes[] = '_vti_log'; $excludes[] = '_vti_pvt'; $excludes[] = '_vti_txt'; #30 $excludes[] = '_vxi_txt'; $excludes[] = 'css'; $excludes[] = 'img'; $excludes[] = 'images'; $excludes[] = 'js'; $excludes[] = 'cgi'; $excludes[] = 'cgi-bin'; $excludes[] = 'ssfm'; $ls = scandir(dirname(__FILE__)); echo 'table border=1 cellspacing=5 cellpadding=0 bgcolor=E0E0E0tr align=center'; #40 foreach ($ls as $d) { if (is_dir($d) !preg_match('/^\./',basename($d)) !in_array(basename($d),$excludes)) { echo 'td'.$d.'bra href='.$d.'img src=/Categories/'.$d.'/thumb.png border=5/abr'; include($d./desc.txt); echo '/td'; }; }; echo '/tr/table'; ? Now I am stymied on changing this to add /trtr at the right points in the structure. I am new to php, and welcome all suggestions and gainful comments. You want modulo math... Check out this page http://www.cmsws.com/examples/php/modulo_array_output.php If you like the output, here is the source http://www.cmsws.com/examples/php/modulo_array_output.phps The bottom two examples show how you can use other HTML tags to present data. Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] code quest
Very nice; I am leaning in the direction of doing it this way. Thank you! :-) On 2/14/2011 9:24 PM, Jim Lucas wrote: On 2/14/2011 4:53 PM, Kirk Bailey wrote: Now I have a situation. I need to take the code from my former home page and modify it to lay out a table (let's say 5 cells wide) and as many rows deep to contain all the items. Each item is the name of the directory, under which is an icon image from that directory, under which is a description file read from that directory. Here is my code thus far: ?php # The next several lines declare an array of directories which are NOT to be listed!# $excludes[] = 'attachments'; #20 $excludes[] = 'data'; $excludes[] = 'include'; $excludes[] = 'resources'; $excludes[] = 'stats'; $excludes[] = '_private'; $excludes[] = '_vti_bin'; $excludes[] = '_vti_cnf'; $excludes[] = '_vti_log'; $excludes[] = '_vti_pvt'; $excludes[] = '_vti_txt'; #30 $excludes[] = '_vxi_txt'; $excludes[] = 'css'; $excludes[] = 'img'; $excludes[] = 'images'; $excludes[] = 'js'; $excludes[] = 'cgi'; $excludes[] = 'cgi-bin'; $excludes[] = 'ssfm'; $ls = scandir(dirname(__FILE__)); echo 'table border=1 cellspacing=5 cellpadding=0 bgcolor=E0E0E0tr align=center'; #40 foreach ($ls as $d) { if (is_dir($d) !preg_match('/^\./',basename($d)) !in_array(basename($d),$excludes)) { echo 'td'.$d.'bra href='.$d.'img src=/Categories/'.$d.'/thumb.png border=5/abr'; include($d./desc.txt); echo '/td'; }; }; echo '/tr/table'; ? Now I am stymied on changing this to add/trtr at the right points in the structure. I am new to php, and welcome all suggestions and gainful comments. You want modulo math... Check out this page http://www.cmsws.com/examples/php/modulo_array_output.php If you like the output, here is the source http://www.cmsws.com/examples/php/modulo_array_output.phps The bottom two examples show how you can use other HTML tags to present data. Jim Lucas -- 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 - ECHO?!?
Kirk Bailey wrote: Ok, so what is echo, and how is it different from print. The code in code quest used echo. I have a copy of learning php 5.0 from O'Reilly, and noplace does it mention echo. Why? What's the difference? IS there a difference? Is there an advantage to either? Please clarify for this newbie. The documentation says it all better than I can: http://php.net/manual/en/function.echo.php http://php.net/manual/en/function.print.php Cheers -- David Robley OPERATOR! Trace this call and tell me where I am. Today is Sweetmorn, the 54th day of The Aftermath in the YOLD 3176. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] code quest - ECHO?!?
Groovy; they appear to be identical in all but name. IDENTICAL. Or am I missing a subtle definition difference? David Robley wrote: Kirk Bailey wrote: Ok, so what is echo, and how is it different from print. The code in code quest used echo. I have a copy of learning php 5.0 from O'Reilly, and noplace does it mention echo. Why? What's the difference? IS there a difference? Is there an advantage to either? Please clarify for this newbie. The documentation says it all better than I can: http://php.net/manual/en/function.echo.php http://php.net/manual/en/function.print.php Cheers -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht +-+ | BOX | +-+ think
Re: [PHP] code quest - ECHO?!?
They are almost identical. Echo supports multiple parameters like echo $a, $b; print is 20% slower than echo (by some tests). echo is shorter than print so it's easy to write. In fact it's all a matter of taste. The same reason we user die instead of exit. Alex On Sun, Dec 12, 2010 at 6:23 PM, Kirk Bailey kbai...@howlermonkey.netwrote: Groovy; they appear to be identical in all but name. IDENTICAL. Or am I missing a subtle definition difference? David Robley wrote: Kirk Bailey wrote: Ok, so what is echo, and how is it different from print. The code in code quest used echo. I have a copy of learning php 5.0 from O'Reilly, and noplace does it mention echo. Why? What's the difference? IS there a difference? Is there an advantage to either? Please clarify for this newbie. The documentation says it all better than I can: http://php.net/manual/en/function.echo.php http://php.net/manual/en/function.print.php Cheers -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht+-+ | BOX | +-+think
Re: [PHP] code quest - ECHO?!?
And the obvious difference, print returns true on success. I'm not sure what would cause an echo it print to ever fail, so it really doesn't make a huge difference. Thanks, Ash http://www.ashleysheridan.co.uk - Reply message - From: Alexandru Patranescu dreal...@gmail.com Date: Sun, Dec 12, 2010 18:56 Subject: [PHP] code quest - ECHO?!? To: Kirk Bailey kbai...@howlermonkey.net Cc: php-general@lists.php.net They are almost identical. Echo supports multiple parameters like echo $a, $b; print is 20% slower than echo (by some tests). echo is shorter than print so it's easy to write. In fact it's all a matter of taste. The same reason we user die instead of exit. Alex On Sun, Dec 12, 2010 at 6:23 PM, Kirk Bailey kbai...@howlermonkey.netwrote: Groovy; they appear to be identical in all but name. IDENTICAL. Or am I missing a subtle definition difference? David Robley wrote: Kirk Bailey wrote: Ok, so what is echo, and how is it different from print. The code in code quest used echo. I have a copy of learning php 5.0 from O'Reilly, and noplace does it mention echo. Why? What's the difference? IS there a difference? Is there an advantage to either? Please clarify for this newbie. The documentation says it all better than I can: http://php.net/manual/en/function.echo.php http://php.net/manual/en/function.print.php Cheers -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht+-+ | BOX | +-+think
Re: [PHP] code quest - ECHO?!?
Ok, so what is echo, and how is it different from print. The code in code quest used echo. I have a copy of learning php 5.0 from O'Reilly, and noplace does it mention echo. Why? What's the difference? IS there a difference? Is there an advantage to either? Please clarify for this newbie. -- 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
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 'ul' for dir in ALIST: print 'lia href=\/dir,dir,'/a print '/ul 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 ul/ul if you have no directories returned by glob(). print('ul'); foreach ( glob('./*', GLOB_ONLYDIR) AS $dir ) print('lia href=\'.$dir.'\'.$dir.'/a/li'); print('/ul'); 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 kbai...@howlermonkey.net 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: ?php $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 'lia href='.$d.''.$d.'/abr/'.PHP_EOL; } } ? -- /Daniel P. Brown 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: *ul ?php # The next several lines declare an array of directories 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 'lia href='.$d.''.$d.'/abr/'.PHP_EOL; } } ? /ul* 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 kbai...@howlermonkey.net 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: ?php $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 'lia href='.$d.''.$d.'/abr/'.PHP_EOL; } } ? -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht +-+ | BOX | +-+ think
Re: [PHP] code quest
From: Kirk Bailey kbai...@howlermonkey.net 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. -- 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?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 'lia href='.$d.''.$d.'/abr/'.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 'lia href='.$d.''.include($d.'desc.txt').'/abr/'.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 kbai...@howlermonkey.net 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
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: ?php # The next several lines declare an array of directories 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 'lia href='.$d.''.include('./'.$d.'/desc.txt') ;#.'/abr/'.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?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 'lia href='.$d.''.$d.'/abr/'.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 'lia href='.$d.''.include($d.'desc.txt').'/abr/'.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 kbai...@howlermonkey.net 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
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: ?php # The next several lines declare an array of directories 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 'lia href='.$d.''.include('./'.$d.'/desc.txt') ;#.'/abr/'.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 'lia href='.$d.''; include('./'.$d.'/desc.txt'); echo '/a/libr /'.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?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 'lia href='.$d.''.$d.'/abr/'.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 'lia href='.$d.''.include($d.'desc.txt').'/abr/ '.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 kbai...@howlermonkey.net 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 -- 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: ?php # The next several lines declare an array of directories 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 'lia href='.$d.''; echo include($d.'/desc.txt' ); echo '/abr/'.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: ?php # The next several lines declare an array of directories 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 'lia href='.$d.''.include('./'.$d.'/desc.txt') ;#.'/abr/'.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 'lia href='.$d.''; include('./'.$d.'/desc.txt'); echo '/a/libr /'.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?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 'lia href='.$d.''.$d.'/abr/'.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 'lia href='.$d.''.include($d.'desc.txt').'/abr/'.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 kbai...@howlermonkey.net 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 -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht
Re: [PHP] code quest
On 4 December 2010 20:58, Kirk Bailey kbai...@howlermonkey.net wrote: the code is now: ?php # The next several lines declare an array of directories 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 'lia href='.$d.''; echo include($d.'/desc.txt' ); echo '/abr/'.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: ?php # The next several lines declare an array of directories 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 'lia href='.$d.''.include('./'.$d.'/desc.txt') ;#.'/abr/'.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 'lia href='.$d.''; include('./'.$d.'/desc.txt'); echo '/a/libr /'.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?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 'lia href='.$d.''.$d.'/abr/'.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 'lia href='.$d.''.include($d.'desc.txt').'/abr/'.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 kbai...@howlermonkey.net 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 -- end Very Truly yours, - Kirk
Re: [PHP] code quest
On Sat, Dec 4, 2010 at 15:58, Kirk Bailey kbai...@howlermonkey.net 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. -- /Daniel P. Brown 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: ?php # The next several lines declare an array of directories 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 'lia href='.$d.''; echo include($d.'/desc.txt' ); There should be no echo here echo '/abr/'.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: ?php # The next several lines declare an array of directories 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 'lia href='.$d.''.include('./'.$d.'/desc.txt') ;#.'/abr/'.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 'lia href='.$d.''; include('./'.$d.'/desc.txt'); echo '/a/libr /'.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?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 'lia href='.$d.''.$d.'/abr/'.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 'lia href='.$d.''.include($d.'desc.txt').'/abr/ '.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 kbai...@howlermonkey.net 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 -- end Very Truly yours, - Kirk Bailey, Largo
Re: [PHP] code quest
On Wed, Dec 1, 2010 at 23:13, Kirk Bailey kbai...@howlermonkey.net 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: ?php $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 'lia href='.$d.''.$d.'/abr/'.PHP_EOL; } } ? -- /Daniel P. Brown 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 Thu, 2010-12-02 at 10:07 -0500, Daniel P. Brown wrote: On Wed, Dec 1, 2010 at 23:13, Kirk Bailey kbai...@howlermonkey.net 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: ?php $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 'lia href='.$d.''.$d.'/abr/'.PHP_EOL; } } ? -- /Daniel P. Brown 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 :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] code quest
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 'ul' for dir in ALIST: print 'lia href=\/dir,dir,'/a print '/ul 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 ul/ul if you have no directories returned by glob(). print('ul'); foreach ( glob('./*', GLOB_ONLYDIR) AS $dir ) print('lia href=\'.$dir.'\'.$dir.'/a/li'); print('/ul'); Jim Lucas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] code quest
Daniel, this is so close to bang on it's unbelivable. Only prob is my host provided me with this $^@%^^$! dir which is named .smileys, which holds icons for use in the control panel. It should NOT list it, nor list the /cgi-bin, nor /images. Can it somehow exclude those 3, or maybe a list of things not to notice? Also, how compatible is it with SSI includes? If part of the echo is an ssi include statement, will it work right? Hmmm... Daniel P. Brown wrote: On Fri, Nov 26, 2010 at 19:03, Kirk Bailey kbai...@howlermonkey.net wrote: 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. Simple: ?php $ls = scandir(dirname(__FILE__)); foreach ($ls as $d) { if (is_dir($d) $d != '.' $d != '..') { echo 'a href='.$d.''.$d.'/abr/'.PHP_EOL; } } ? If you want something more powerful - and often quicker - check into SPL: specifically FilesystemIterator[1], DirectoryIterator[2], and RecursiveDirectoryIterator[3]. A quick example to link all child files and directories with relative linking: ?php $path = dirname(__FILE__); $list = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path)); foreach ($list as $k = $v) { if (!preg_match('/\./',$v)) { $v = str_replace($path.'/',null,$v); // We only want relative linking echo 'a href='.$v.''.$v.'/abr/'.PHP_EOL; } } ? -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht +-+ | BOX | +-+ think
Re: [PHP] code quest
OK, answered my own question; no, an ssi statement inside a php echo statement is simply sent out as is, unparxsed. But if it is external to the php area, it works fine, so we have to include a function in there that will read anything I want to spew- like the 1 line contents of a desciptor file in a particular directory. The idea is to create a directory lister which reads a descriptor for that folder and uses it as the text for the link. Daniel P. Brown wrote: On Sat, Nov 27, 2010 at 12:36, Daniel P. Brown daniel.br...@parasane.net wrote: If you want something more powerful - and often quicker - check into SPL: specifically FilesystemIterator[1], DirectoryIterator[2], and RecursiveDirectoryIterator[3]. A quick example to link all child files and directories with relative linking: Might help to provide the key as well, eh? Sorry ^1: http://php.net/filesystemiterator ^2: http://php.net/directoryiterator ^3: http://php.net/recursivedirectoryiterator -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht +-+ | BOX | +-+ think
Re: [PHP] code quest
OK, the quest thus far: html head TITLEphp experimental page/TITLE style TYPE=text/css body { margin-left: 5%; margin-right: 5%; } A:link, A:visited, A:active { text-decoration:none; } A:hover { text-decoration:underline; } /style /head BODY text=00 bgcolor=FF h2 align=centerSubdirectory listing experimental menuing page/h1P ul ?php $ls = scandir(dirname(__FILE__)); foreach ($ls as $d) { if (is_dir($d) $d != '.' $d != '..') { echo 'lia href='.$d.''.$d.'/abr/'.PHP_EOL; } } ? /ul P nbsp; /body /html The results may be seen on this page: http://www.howlermonkey.net/dirlisting.php 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. Daniel P. Brown wrote: On Fri, Nov 26, 2010 at 19:03, Kirk Bailey kbai...@howlermonkey.net wrote: 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 lev 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
On Fri, 2010-11-26 at 20:27 -0500, Bastien wrote: On 2010-11-26, at 7:33 PM, Adam Richardson simples...@gmail.com wrote: On Fri, Nov 26, 2010 at 7:03 PM, Kirk Bailey kbai...@howlermonkey.netwrote: 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 'ul' for dir in ALIST: print 'lia href=\/dir,dir,'/a print '/ul 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? -- 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 To get you started: function get_directories($path) { $files_and_dirs = scandir($path); $dirs = array_filter($files_and_dirs, function($elem) { return is_dir($elem); }); // $dirs also contains . and .., but you can get rid of them quite easily return $dirs; } Happy coding :) Adam -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com Code igniter, a php framework can do this with one call. It could be worth looking into Bastien Koert 905-904-0334 Sent from my iPhone I'm not sure CodeIgniter would be of any help here. I don't recall any function in the CodeIgniter framework that lists directories like this, so he'd still have to end up coding it himself. Also, python tends to be used more for command line stuff than websites. CodeIgniter does have a CLI extension, but the app would just be severely bloated running an entire PHP framework for what might only need a light script. Bit like using a sledgehammer to hammer in a thumb tack, can be done, but not really the best tool for the job. Thanks, Ash http://www.ashleysheridan.co.uk
Re: [PHP] code quest
On Sat, Nov 27, 2010 at 12:36, Daniel P. Brown daniel.br...@parasane.net wrote: If you want something more powerful - and often quicker - check into SPL: specifically FilesystemIterator[1], DirectoryIterator[2], and RecursiveDirectoryIterator[3]. A quick example to link all child files and directories with relative linking: Might help to provide the key as well, eh? Sorry ^1: http://php.net/filesystemiterator ^2: http://php.net/directoryiterator ^3: http://php.net/recursivedirectoryiterator -- /Daniel P. Brown 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 Fri, Nov 26, 2010 at 7:03 PM, Kirk Bailey kbai...@howlermonkey.netwrote: 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 'ul' for dir in ALIST: print 'lia href=\/dir,dir,'/a print '/ul 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? -- 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 To get you started: function get_directories($path) { $files_and_dirs = scandir($path); $dirs = array_filter($files_and_dirs, function($elem) { return is_dir($elem); }); // $dirs also contains . and .., but you can get rid of them quite easily return $dirs; } Happy coding :) Adam -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com
Re: [PHP] code quest
On 2010-11-26, at 7:33 PM, Adam Richardson simples...@gmail.com wrote: On Fri, Nov 26, 2010 at 7:03 PM, Kirk Bailey kbai...@howlermonkey.netwrote: 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 'ul' for dir in ALIST: print 'lia href=\/dir,dir,'/a print '/ul 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? -- 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 To get you started: function get_directories($path) { $files_and_dirs = scandir($path); $dirs = array_filter($files_and_dirs, function($elem) { return is_dir($elem); }); // $dirs also contains . and .., but you can get rid of them quite easily return $dirs; } Happy coding :) Adam -- Nephtali: PHP web framework that functions beautifully http://nephtaliproject.com Code igniter, a php framework can do this with one call. It could be worth looking into Bastien Koert 905-904-0334 Sent from my iPhone -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php