I am trying to access a file list on a FTP server. My code is working fine but all results are showing on one line, I want links displayed as links, one per line.
This is what I tried:
$ftp_server = "abc";
$ftp_user = "xyz";
$ftp_password = "123";
$path = "/";
if(ftp_login($conn,$ftp_user,$ftp_password))
{
$contents= ftp_nlist($conn, $path);
echo implode("\n",$contents) ;
}
?>
results are like:
file1 file2 file3
I want it to be like:
file1
file2
file3
If you are on Windows you may actually need \\r\\n
instead of just \\n
due to the way that Windows handles new lines.
PHP has a handy constant called PHP_EOL
which will automatically use the correct one.
If you are outputting the text in HTML
then rather than a new line, you actually need to separate each file with a line break. The HTML
for a line break is <br>
.
Try the following to see which one works for you.
echo implode(PHP_EOL, $contents); // New line
echo implode('<br>', $contents); // HTML line break
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.