到目前为止,我的代码是从.txt文件中读取,通过html解析信息和输出.我的问题是如何将我的$ name和$ email变量回显到一个双列表中?
这是我的代码:
<?php
// Read the file into an array
$users = file("names.txt");
// Cycle through the array
foreach ($users as $user) {
// Parse the line, retriving the name and e-mail address
list($name, $email) = explode(" ", $user);
// Remove newline from $email
$email = trim($email);
// Output the data...how could I do this with a two-column table?
echo "<a href=\"mailto:$email\">$name</a> <br />";
}
?>
Run Code Online (Sandbox Code Playgroud)
提前致谢.
只需添加一些标记
// Read the file into an array
$users = file("names.txt");
if (count($users)) {
// Open the table
echo "<table>";
// Cycle through the array
foreach ($users as $user) {
// Parse the line, retriving the name and e-mail address
list($name, $email) = explode(" ", $user);
// Remove newline from $email
$email = trim($email);
// Output a row
echo "<tr>";
echo "<td>$name</td>";
echo "<td><a href=\"mailto:$email\">$email</a></td>";
echo "</tr>";
}
// Close the table
echo "</table>";
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
73519 次 |
| 最近记录: |