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

我需要在输出中的一组文本文件中分隔换行符。目前,我们可以分块显示网页上文件夹中的所有文本文件,但是文本数据组合在文本块中,我想学习如何识别换行符并将显示的内容向下移动一两行创建一个易于阅读的分隔符。


我没有尝试任何东西,因为我对如何识别换行符并显示它感到困惑。


$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.


慕工程0101907
浏览 221回答 2
2回答

holdtom

<?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"&nbsp;cellpadding="4" bgcolor="#fff" id="rcorners">';foreach ($items as $item) {**echo"<tr><td id='rcorners'>".nl2br($item)."</td></tr>\n";**}echo '</table>';}}closedir($dir);?>
打开App,查看更多内容
随时随地看视频慕课网APP