Jump to content

[SOLVED] line breaks in between fetched file names


xait

Recommended Posts

Hi,

 

I have this code:

<?php 
if($dir = opendir('files')){
   while (($file = readdir($dir) )!== false){
          if ($file !='.' && $file !='..'){
               echo '<a href="' . $file . '">' . $file . '</a>';"\n";
		   
          }
}
closedir($dir);
}
?>

 

but when it outputs the files from the files folder, it lists them one after another with no spaces etc. How can I make it list one file per line?

 

e.g.

file_1.doc

file_2.png

file_3.exe

 

Thanks, Wez

 

 

Firstly that \n will do nothing, it's not actually attacked to the echo statement it's just a string floating to oblivion in your code. But even if you had go that right HTML ignores such characters. You could either include the <a ... ></a> element inside a block element such as <li> to create a list of them. You could style the <a ...></a> element to be a block element itself, or you could append <br/> to the end of the string (it's the HTML equivalent of \n).

 

echo '<a href="' . $file . '">' . $file . '</a><br/>';

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.