亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

從文本文件目錄中讀取文件內容時,文本文件中的單獨換行符(新行向下)

從文本文件目錄中讀取文件內容時,文本文件中的單獨換行符(新行向下)

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 關注
  • 237 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號