如何將一個文本內容通過PHP 以表格的方式輸入到頁面上
<?php //讀取文本內容 $contents = file_get_contents("names.txt"); //分割字符串 $lines = explode("\n",trim($contents)); foreach ($lines as $row) { $data[]=explode('|',$row); } ?> <!-- 將文本內容放入表格中 --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>人員名單</title> </head> <body> <h1>人員名單</h1> <table> <thead> <th>編號</th> <th>姓名</th> <th>年齡</th> <th>郵箱</th> <th>網址</th> <tbody> <?php foreach ($data as $row): ?> <tr> <?php foreach ($row as $col): ?> <?php $col=trim($col) ?> <?php if (strpos($col, 'http://')===0): ?> <td><a href="<?php echo strtolower($col)?>"><?php echo substr(strtolower($col),7); ?></a></td> <?php else: ?> <td><?php echo $col;?></td> <?php endif ?> <?php endforeach ?> </tr> <?php endforeach ?> </tbody> </thead> </table> </body> </html>
具體看代碼 @不懂的留言!