在PHP中,可以使用HTML的<table>标签来创建表格,并使用CSS来设置字体样式。以下是一个示例代码:
<!DOCTYPE html>
<html>
<head>
<style>
table {
font-family: Arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
</style>
</head>
<body>
<?php
// 创建一个二维数组作为数据源
$data = array(
array("John", "Doe", "john@example.com"),
array("Jane", "Smith", "jane@example.com"),
array("Bob", "Johnson", "bob@example.com")
);
?>
<table>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Email</th>
</tr>
<?php
// 遍历数据源,并输出表格行
foreach ($data as $row) {
echo "<tr>";
foreach ($row as $cell) {
echo "<td>" . $cell . "</td>";
}
echo "</tr>";
}
?>
</table>
</body>
</html>
在上面的代码中,我们使用了CSS样式来设置表格的字体为Arial,sans-serif,并设置了表格的边框样式、宽度和背景颜色。在PHP中,使用echo语句输出HTML代码来生成表格。
上一篇:php中的延迟绑定
下一篇:php 调用阿里云接口
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站