gpt4 book ai didi

php - PHP 中的回显表

转载 作者:行者123 更新时间:2023-11-28 03:58:01 25 4
gpt4 key购买 nike

到目前为止,我的代码可以从 .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 />";

}

?>

提前致谢。

最佳答案

只需添加一些标记

// 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>";
}

关于php - PHP 中的回显表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7907807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com