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

  具体看代码 @不懂的留言!

相关文章:

  • 2021-09-11
  • 2021-09-06
  • 2021-06-04
  • 2021-09-18
  • 2022-12-23
  • 2021-08-31
  • 2021-11-01
  • 2022-01-15
猜你喜欢
  • 2022-01-16
  • 2022-01-31
  • 2022-02-08
  • 2021-06-25
  • 2022-02-13
  • 2021-10-16
  • 2022-01-19
相关资源
相似解决方案