PHP如何将文本内容以表格的方式展现到HTML页面上

今天就跟大家聊聊有关PHP如何将文本内容以表格的方式展现到HTML页面上,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

<?php
//读取文本内容
$contents = file_get_contents("names.txt");
//分割字符串
$lines = explode("\n",trim($contents));
foreach ($lines as $row) {
	$data[]=explode('|',$row);
}
?>

相关教程:PHP视频教程

<!-- 将文本内容放入表格中 --> 
<!DOCTYPE html> 
<html> 
<head> 
 <meta charset="UTF-8"> 
 <title>人员名单</title> 
</head> 
<body> 
 <h2>人员名单</h2> 
 <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>

看完上述内容,你们对PHP如何将文本内容以表格的方式展现到HTML页面上有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注行业资讯频道,感谢大家的支持。