xait Posted October 31, 2009 Share Posted October 31, 2009 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 Link to comment https://forums.phpfreaks.com/topic/179723-solved-line-breaks-in-between-fetched-file-names/ Share on other sites More sharing options...
cags Posted October 31, 2009 Share Posted October 31, 2009 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/>'; Link to comment https://forums.phpfreaks.com/topic/179723-solved-line-breaks-in-between-fetched-file-names/#findComment-948270 Share on other sites More sharing options...
xait Posted October 31, 2009 Author Share Posted October 31, 2009 Thanks, that n wasn't supposed to be there :-) I was just trying it to see if it worked ,and copied it by mistake. thanks for help though Link to comment https://forums.phpfreaks.com/topic/179723-solved-line-breaks-in-between-fetched-file-names/#findComment-948292 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.