当前位置: 移动技术网 > IT编程>开发语言>PHP > 如何将一个文本内容通过PHP 以表格的方式输入到页面上

如何将一个文本内容通过PHP 以表格的方式输入到页面上

2018年08月27日  | 移动技术网IT编程  | 我要评论

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

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网