note 73085 added to function.opendir
| From: | NerdyDork at osu1 dot php dot net | Date: | Thu, 08 Feb 2007 16:36:28 +0000 |
| Subject: | note 73085 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123124@lists.php.net to get a copy of this message | ||
Here is a snippet to create a site map of all html files in a folder:
<?php
// read all html file in the current directory
if ($dh = opendir('./')) {
$files = array();
while (($file = readdir($dh)) !== false) {
if (substr($file, strlen($file) - 5) == '.html') {
array_push($files, $file);
}
}
closedir($dh);
}
// Sort the files and display
sort($files);
echo "<ul>\n";
foreach ($files as $file) {
$title = Title($file);
echo "<li><a href=\"$file\"
title=\"$title\">$title</a></li>\n";
}
echo "</ul>\n";
// Function to get a human readable title from the filename
function Title($filename) {
$title = substr($filename, 0, strlen($filename) - 5);
$title = str_replace('-', ' ', $title);
$title = ucwords($title);
return $title;
}
?>
----
Server IP: 216.194.113.175
Probable Submitter: 65.103.238.206
----
Manual Page -- http://www.php.net/manual/en/function.opendir.php
Edit -- https://master.php.net/note/edit/73085
Del: integrated -- https://master.php.net/note/delete/73085/integrated
Del: useless -- https://master.php.net/note/delete/73085/useless
Del: bad code -- https://master.php.net/note/delete/73085/bad+code
Del: spam -- https://master.php.net/note/delete/73085/spam
Del: non-english -- https://master.php.net/note/delete/73085/non-english
Del: in docs -- https://master.php.net/note/delete/73085/in+docs
Del: other reasons-- https://master.php.net/note/delete/73085
Reject -- https://master.php.net/note/reject/73085
Search -- https://master.php.net/manage/user-notes.php