为了账号安全,请及时绑定邮箱和手机立即绑定

从文本文件目录中读取文件内容时,文本文件中的单独换行符(新行向下)

从文本文件目录中读取文件内容时,文本文件中的单独换行符(新行向下)

PHP
慕工程0101907 2021-07-05 10:55:15
我需要在输出中的一组文本文件中分隔换行符。目前,我们可以分块显示网页上文件夹中的所有文本文件,但是文本数据组合在文本块中,我想学习如何识别换行符并将显示的内容向下移动一两行创建一个易于阅读的分隔符。我没有尝试任何东西,因为我对如何识别换行符并显示它感到困惑。$directory = "feeds/";$dir = opendir($directory);while (($file = readdir($dir)) !== false) {  $filename = $directory . $file;  $type = filetype($filename);  if ($type == 'file') {     $contents = file_get_contents($filename);     $items = explode('/n', $contents);     echo '<table width="100%" border="1" cellpadding="4" bgcolor="#fff">';     foreach ($items as $item) {       echo "<tr><td>$item</td></tr>\n";     }     echo '</table>';  }}closedir($dir);?>```Output at the moment is this@mpgradio - Mark Rogers - Imagining playing on MPG Radios.. Innovative Music Mix - http://www.mpgradio.ca/radio/imm/ Your music could be included in our rotations, just reach out to us. @lacroix_gen - Gen Lacroix - l’extase de l’oubli playing on MPG Radios.. Reflection Town - http://www.mpgradio.ca/radio/rt/ Where you have the opportunity to listen to unsigned independent artists.Expected output is would be something like.@mpgradio - Mark Rogers - Imagining playing on MPG Radios.. Innovative Music Mix - http://www.mpgradio.ca/radio/imm/ Your music could be included in our rotations, just reach out to us.@lacroix_gen - Gen Lacroix - l’extase de l’oubli playing on MPG Radios.. Reflection Town - http://www.mpgradio.ca/radio/rt/ Where you have the opportunity to listen to unsigned independent artists.
查看完整描述

2 回答

?
holdtom

TA贡献1805条经验 获得超10个赞

<?php

$directory = "feeds/";

$dir = opendir($directory);

while (($file = readdir($dir)) !== false) {

$filename = $directory . $file;

$type = filetype($filename);

if ($type == 'file') {

$contents = file_get_contents($filename);

$items = explode('\n', $contents);

echo '<table width="100%" border="1" 


cellpadding="4" bgcolor="#fff" id="rcorners">';

foreach ($items as $item) {

**echo"<tr><td id='rcorners'>".nl2br

($item)."</td></tr>\n";**


}

echo '</table>';

}

}

closedir($dir);

?>


查看完整回答
反对 回复 2021-07-09
  • 2 回答
  • 0 关注
  • 220 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信