如何将一个文本内容通过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>
< charset="UTF-8">
< >人员名单</ >
</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>
具体看代码 @不懂的留言!
继续阅读与本文标签相同的文章
-
阿里云RDS for SQL Server购买使用流程
2026-05-18栏目: 教程
-
阿里云智能战略与合作部刘湘雯:阿里关于创新创业服务的思考
2026-05-18栏目: 教程
-
阿里未来酒店王群:让天下没有难住的酒店
2026-05-18栏目: 教程
-
免费下载!《阿里工程师的自我修养》公开10位阿里大牛解决问题的思维方式
2026-05-18栏目: 教程
-
BAT技术面dubbo还能这么问?
2026-05-18栏目: 教程
