Hi There -
Am trying to list all of the items in a directory, with each item on a new line.
The backslash r backslash n in double quotes is giving me no new line.
One of the things that may be a problem is a double necessity for double quotes. I've tried several ways to fix this. Quotes have always been dastardly for me.
Any help will be gratefully accepted.
Thanks,
Lee
Code below.
<?php
// name this file index.php and include it inside the directory you want the list from
// open the current directory
$dhandle = opendir('.');
// define an array to hold the files
$files = array();
if ($dhandle) {
// loop through all of the files
while (false !== ($fname = readdir($dhandle))) {
// if the file is not this file, and does not start with a '.' or '..',
// then store it for later display
if (($fname != '.') && ($fname != '..') &&
($fname != basename($_SERVER['PHP_SELF']))) {
// store the filename
$files[] = (is_dir( "./$fname" )) ? "(Dir) {$fname}" : $fname;
}
}
// close the directory
closedir($dhandle);
}
$newline="\r\n";
// Now loop through the files, with a new line after each one
foreach( $files as $fname )
{
echo "$fname $newline";
}
?>