note 76071 added to function.scandir

From: Date: Thu, 28 Jun 2007 19:51:25 +0000
Subject: note 76071 added to function.scandir
Groups: php.notes 
Request: Send a blank email to php-notes+get-128062@lists.php.net to get a copy of this message
Saw banzai monkeys code and tweaked it a little. I don't have scandir. So I had to play with the suggested use for php4. Pretty new to PHP so beer with me. This will show your current directory as a link called "Back" and will list all of your files in a menu. I wanted this because I have a lot of static pages and needed a menu that would auto update every time I added a file. <?php $current=getcwd(); $directory=basename($current); $direct=str_replace('-',' ',$directory); $directoryuppercasewords=ucwords($direct); /*this first section above will get your current folder or directory and since I have a "-" between the words of my file I have to strip them to look good if I want to show the current folder or directory in the title of the first link */ $dir = '.'; $dh = opendir($dir); while (false !== ($filename = readdir($dh))) { $files[] =$filename; } $t=array_slice($files,2); $f=array_search('index.php',$t); /*this code above with the variable $t gets rid of the '.' and the '..' parent and ancestor files. And the variable $f finds the index file and with the code below 'unset' let you use $f as the key to get rid of that file. */ unset($t[$f]); print('<ul align="left">'); print('<li><a href="." title="'.$directoryuppercasewords.'">Back</a></br></li>'); foreach($t as $key => $value){ $phpkill=str_replace('.php', '', $value); $htmlkill=str_replace('.html', '', $phpkill); $dashkill=str_replace('-',' ',$htmlkill); $uppercasewords=ucwords($dashkill); print('<li><a href="' . $dir . '/' . $value . '" title="'.$uppercasewords.'>' . $uppercasewords . "</a></br></li>"); } print('</ul>'); closedir($dh); ?> I basically made all the variables so they could explain themselves, Regular expression is not my strong point right now, just becoming familiar with php functions is more of a priority, I hope this is usefull to someone. ---- Server IP: 64.71.164.2 Probable Submitter: 216.57.86.104 ---- Manual Page -- http://www.php.net/manual/en/function.scandir.php Edit -- https://master.php.net/note/edit/76071 Del: integrated -- https://master.php.net/note/delete/76071/integrated Del: useless -- https://master.php.net/note/delete/76071/useless Del: bad code -- https://master.php.net/note/delete/76071/bad+code Del: spam -- https://master.php.net/note/delete/76071/spam Del: non-english -- https://master.php.net/note/delete/76071/non-english Del: in docs -- https://master.php.net/note/delete/76071/in+docs Del: other reasons-- https://master.php.net/note/delete/76071 Reject -- https://master.php.net/note/reject/76071 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#128062) next »