如何將一個文本內容通過PHP 以表格的方式輸入到頁面上


如何將一個文本內容通過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>

  具體看代碼 @不懂的留言!


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM