如何将一个文本内容通过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