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

little bottle
Release: 2023-04-06 11:10:02
forward
3301 people have browsed it

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);
}
?>
Copy after login

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>
Copy after login

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!

Related labels:
source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!