Home >Backend Development >PHP Tutorial >How to use PHP to display text content as a table on an HTML page

How to use PHP to display text content as a table on an HTML page

little bottle
little bottleforward
2019-04-25 15:39:063434browse

This article describes how to use PHP to display text content in a table on an HTML page. It has certain reference value and interested friends can refer to it.


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

Related tutorials: PHP video tutorial

<!-- 将文本内容放入表格中 --> 
<!DOCTYPE html> 
<html> 
<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, &#39;http://&#39;)===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>

Related tutorials: HTML video tutorial

The above is the detailed content of How to use PHP to display text content as a table on an HTML page. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete