PHP 中的回显表

发布于 2024-12-11 19:31:47 字数 590 浏览 0 评论 0原文

到目前为止,我的代码可以从 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

捎一片雪花 2024-12-18 19:31:48

只需添加一些标记

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

just add some markup

// 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>";
}
混浊又暗下来 2024-12-18 19:31:48

表格如下所示:

<table>
   <tr>
     <td>...</td>
     <td>...</td>
     <td>...</td>
   </tr>
   ...
</table>

使用 php 的功能将 trtd 放置在 for 循环内部和外部。

A table looks like this:

<table>
   <tr>
     <td>...</td>
     <td>...</td>
     <td>...</td>
   </tr>
   ...
</table>

Use the powers of php to put tr and td's where they should be, inside and outside the for loop.

够钟 2024-12-18 19:31:48

你的意思是更多这样的吗?

<?php

// Read the file into an array
$users = file("names.txt");
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 the data...how could I do this with a two-column table?
    echo "<tr><td>".$name."</td><td>".$email."</td></tr>";

}
echo "</table>";
?>

do you mean more like this?

<?php

// Read the file into an array
$users = file("names.txt");
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 the data...how could I do this with a two-column table?
    echo "<tr><td>".$name."</td><td>".$email."</td></tr>";

}
echo "</table>";
?>
笨死的猪 2024-12-18 19:31:48

使用类似这样的内容:


<?php

// Read the file into an array
$users = file("names.txt");

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 the data...how could I do this with a two-column table?
    echo "<tr><td>$email</td><td>$name</td></tr>";

}

echo "</table>";

?>

基本上,这里发生的是您正在设置一个 HTML 表。用户循环的每次迭代都会添加一个新行,并包含列。

Use something like this:


<?php

// Read the file into an array
$users = file("names.txt");

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 the data...how could I do this with a two-column table?
    echo "<tr><td>$email</td><td>$name</td></tr>";

}

echo "</table>";

?>

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.

浸婚纱 2024-12-18 19:31:48

没什么特别的:

echo '<table>';
foreach($users as #user) {
    # list(…)
    echo '<tr><td>';
    echo htmlspecialchars($name);
    echo '</td><td>';
    echo htmlspecialchars($email);
    echo '</td></tr>';
}
echo '</table>';

Nothing special about it:

echo '<table>';
foreach($users as #user) {
    # list(…)
    echo '<tr><td>';
    echo htmlspecialchars($name);
    echo '</td><td>';
    echo htmlspecialchars($email);
    echo '</td></tr>';
}
echo '</table>';
空心空情空意 2024-12-18 19:31:48
<html>
    <body>

        <table>
            <tr>
                <th>name</th>
                <th>email</th>
            </tr>

            <?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 "<tr>
                    <td>$name</td>
                    <td>$email</td>
                </tr>";
            }
            ?>
        </table>
    </body>
</html>

另请检查此链接 http://www.w3schools.com/html/html_tables.asp

<html>
    <body>

        <table>
            <tr>
                <th>name</th>
                <th>email</th>
            </tr>

            <?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 "<tr>
                    <td>$name</td>
                    <td>$email</td>
                </tr>";
            }
            ?>
        </table>
    </body>
</html>

also check this link http://www.w3schools.com/html/html_tables.asp

于我来说 2024-12-18 19:31:48
echo "<table><thead><tr><th>Name</th><th>Email</th></tr></thead><tbody>";

foreach ($users as $user) {
   //get $email and $name
   echo "<tr><td>$name</td><td><a href="mailto:$email">$email</a></td></tr>";
}
echo "</tbody></table>"
echo "<table><thead><tr><th>Name</th><th>Email</th></tr></thead><tbody>";

foreach ($users as $user) {
   //get $email and $name
   echo "<tr><td>$name</td><td><a href="mailto:$email">$email</a></td></tr>";
}
echo "</tbody></table>"
春花秋月 2024-12-18 19:31:48
    <html>
<head>
<title> TINDAHAN </title>
</head>
<body>

<center> ONLINE GROCERY STORE </center>

<form action = "grocery.php" method ="post">

<table width = "1500" height= "50" border= "0">
<tr>
<td> 
<b> Coffee: </b>;<select name = "coff"> 
<option value = "Nescafe" > Nescafe </option>
<option value = "Blend45" > Blend45 </option>
<option value = "GreatTaste" > Great Taste </option>
<option value = "San Mig" > San Mig </option>
</td>

<td> 
<b> Sugar: </b>;<select name = "sugar">
<option value = "White" > White </option>
<option value = "Brown" > Brown </option>
<option value = "Mascobado" > Mascobado </option>
</td>

<td> 
<b> Milk: </b>;<select name = "milk">
<option value = "BearBrand" > Bear Brand </option>
<option value = "Nido" > Nido </option>
<option value = "Alaska" > Alaska </option>
<option value = "Carnation" > Carnation </option>
</td>
</tr>

<tr>
<td> 
<b> Quantity: </b>;
<input type = "text" name = "acoff" size = "20" maxlength = "40">
</td>

<td> 
<b> Quantity: </b>;
<input type = "text" name = "asugar" size = "20" maxlength = "40">
</td>

<td> 
<b> Quantity: </b>;
<input type = "text" name = "amilk" size = "20" maxlength = "40">
</td>
</tr>

<tr>
<td> 
<b> PRODUCTS: </b>;
NESCAFE - 120 <br>;
BLEND 45 - 90 <br>;
GREAT TASTE - 95 <br>;
SAN MIG - 110 
</td>

<td> 
WHITE - 60/KILO <br> 
BROWN - 45/KILO <br>
MASCOBADO - 90/KILO <br>
</td>

<td> 
BEAR BRAND - 250 <br>
NIDO - 195 <br>
ALASKA - 175 <br>
CARNATION - 25 <br>
</td>
</tr>

<tr>
<td> 
<b> Soap: </b> <select name = "soap"> 
<option value = "Tide" > Tide </option>
<option value = "Ajax" > Ajax </option>
<option value = "Surf" > Surf </option>
<option value = "Pride" > Pride </option>
</td>

<td> 
<b> Cooking Oil: </b> <select name = "oil">
<option value = "Baguio Oil" > Baguio Oil </option>
<option value = "Minola" > Minola </option>
<option value = "Canola" > Canola </option>
<option value = "Olive Oil" > Olive Oil </option>
</td>

<td> 
<b> Toothpaste: </b> <select name = "tp">
<option value = "Colgate" > Colgate </option>
<option value = "Close Up" > Close Up </option>
<option value = "Happee" > Happee </option>
<option value = "Beam" > Beam </option>
</td>
</tr>

<tr>
<td> 
<b> Quantity: </b>
<input type = "text" name = "asoap" size = "20" maxlength = "40">
</td>

<td> 
<b> Quantity: </b>
<input type = "text" name = "aoil" size = "20" maxlength = "40">
</td>

<td> 
<b> Quantity: </b>
<input type = "text" name = "atp" size = "20" maxlength = "40">
</td>
</tr>

<tr>
<td> 
<b> PRODUCTS: </b>
TIDE - 35 <br>
AJAX - 33 <br>
SURF - 32 <br>
PRIDE - 38
</td>

<td> 
BAGUIO OIL - 135 <br> 
MINOLA - 133 <br>
CANOLA - 132 <br>
OLIVE OIL - 238
</td>

<td> 
COLGATE - 185 <br>
CLOSE UP - 197 <br>
HAPPEE - 122 <br>
BEAM - 38 <br>
</td>
</tr>
</table>
<center>
<br>
<br>
<input type = "SUBMIT" name = "submit" value = "SUBMIT">
<center>
</body>
</html>
    <html>
<head>
<title> TINDAHAN </title>
</head>
<body>

<center> ONLINE GROCERY STORE </center>

<form action = "grocery.php" method ="post">

<table width = "1500" height= "50" border= "0">
<tr>
<td> 
<b> Coffee: </b>;<select name = "coff"> 
<option value = "Nescafe" > Nescafe </option>
<option value = "Blend45" > Blend45 </option>
<option value = "GreatTaste" > Great Taste </option>
<option value = "San Mig" > San Mig </option>
</td>

<td> 
<b> Sugar: </b>;<select name = "sugar">
<option value = "White" > White </option>
<option value = "Brown" > Brown </option>
<option value = "Mascobado" > Mascobado </option>
</td>

<td> 
<b> Milk: </b>;<select name = "milk">
<option value = "BearBrand" > Bear Brand </option>
<option value = "Nido" > Nido </option>
<option value = "Alaska" > Alaska </option>
<option value = "Carnation" > Carnation </option>
</td>
</tr>

<tr>
<td> 
<b> Quantity: </b>;
<input type = "text" name = "acoff" size = "20" maxlength = "40">
</td>

<td> 
<b> Quantity: </b>;
<input type = "text" name = "asugar" size = "20" maxlength = "40">
</td>

<td> 
<b> Quantity: </b>;
<input type = "text" name = "amilk" size = "20" maxlength = "40">
</td>
</tr>

<tr>
<td> 
<b> PRODUCTS: </b>;
NESCAFE - 120 <br>;
BLEND 45 - 90 <br>;
GREAT TASTE - 95 <br>;
SAN MIG - 110 
</td>

<td> 
WHITE - 60/KILO <br> 
BROWN - 45/KILO <br>
MASCOBADO - 90/KILO <br>
</td>

<td> 
BEAR BRAND - 250 <br>
NIDO - 195 <br>
ALASKA - 175 <br>
CARNATION - 25 <br>
</td>
</tr>

<tr>
<td> 
<b> Soap: </b> <select name = "soap"> 
<option value = "Tide" > Tide </option>
<option value = "Ajax" > Ajax </option>
<option value = "Surf" > Surf </option>
<option value = "Pride" > Pride </option>
</td>

<td> 
<b> Cooking Oil: </b> <select name = "oil">
<option value = "Baguio Oil" > Baguio Oil </option>
<option value = "Minola" > Minola </option>
<option value = "Canola" > Canola </option>
<option value = "Olive Oil" > Olive Oil </option>
</td>

<td> 
<b> Toothpaste: </b> <select name = "tp">
<option value = "Colgate" > Colgate </option>
<option value = "Close Up" > Close Up </option>
<option value = "Happee" > Happee </option>
<option value = "Beam" > Beam </option>
</td>
</tr>

<tr>
<td> 
<b> Quantity: </b>
<input type = "text" name = "asoap" size = "20" maxlength = "40">
</td>

<td> 
<b> Quantity: </b>
<input type = "text" name = "aoil" size = "20" maxlength = "40">
</td>

<td> 
<b> Quantity: </b>
<input type = "text" name = "atp" size = "20" maxlength = "40">
</td>
</tr>

<tr>
<td> 
<b> PRODUCTS: </b>
TIDE - 35 <br>
AJAX - 33 <br>
SURF - 32 <br>
PRIDE - 38
</td>

<td> 
BAGUIO OIL - 135 <br> 
MINOLA - 133 <br>
CANOLA - 132 <br>
OLIVE OIL - 238
</td>

<td> 
COLGATE - 185 <br>
CLOSE UP - 197 <br>
HAPPEE - 122 <br>
BEAM - 38 <br>
</td>
</tr>
</table>
<center>
<br>
<br>
<input type = "SUBMIT" name = "submit" value = "SUBMIT">
<center>
</body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文