PHP 中的回显表
到目前为止,我的代码可以从 .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 />";
}
?>
提前致谢。
So far, I got my code to read from a .txt file, parse the info and output via html. My question is how can I can echo my $name and $email variables into a two-column table?
Here is my code:
<?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 />";
}
?>
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
只需添加一些标记
just add some markup
表格如下所示:
使用 php 的功能将
tr
和td
放置在 for 循环内部和外部。A table looks like this:
Use the powers of php to put
tr
andtd
's where they should be, inside and outside the for loop.你的意思是更多这样的吗?
do you mean more like this?
使用类似这样的内容:
基本上,这里发生的是您正在设置一个 HTML 表。用户循环的每次迭代都会添加一个新行,并包含列。
Use something like this:
Basically, what's happening here is that you're setting up an HTML table. Each iteration through your user's loop adds a new row, complete with columns.
没什么特别的:
Nothing special about it:
另请检查此链接 http://www.w3schools.com/html/html_tables.asp
also check this link http://www.w3schools.com/html/html_tables.asp