我对 php/mysql 比较陌生。我正在尝试为此部分执行回车:
echo "<td colspan='5'>" . nl2br($row['dish_description']) . "</td>";
“dish_description”包含一些包含“\n”的文本,例如“配沙拉和薄荷酱。\n 包含牛肉。” 但是在 MySQL 数据库中,我无法显示回车符。
<?php
require_once 'login.php';
$con = mysql_connect($db_hostname, $db_username, $db_password);
mysql_select_db($db_database) or die("Unable to select database". mysql_error());
$result = mysql_query("SELECT * FROM `dishes` ORDER BY `dishes`.`dish_id` ASC LIMIT 0 , 200");
echo '<table align="center">
';
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td style='width: 60px'></td>";
echo "<th style='width: 100px'>Dish No</th>";
echo "<td style='width: 70px'>" . $row['dish_id'] . "</td>";
echo "<th style='width: 100px'>Dish Name</th>";
echo "<td style='width: 120px'>" . $row['dish_name'] . "</td>";
echo "<th style='width: 120px'>Dish Price</th>";
echo "<td>£" . $row['dish_price'] . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width: 75px'></td>";
echo "<th style='width: 100px'>Vegetarian</th>";
echo "<td style='width: 70px'>" . $row['dish_vegetarian'] ."</td>";
echo "<td style='width: 100px'></td>";
echo "<td style='width: 70px'></td>";
echo "<th style='width: 120px'>Contains Nuts</th>";
echo "<td style='width: 120px'>" . $row['dish_nuts'] ."</td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width: 75px'></td>";
echo "<th style='width: 100px'>Information</th>";
***echo "<td colspan='5'>" . nl2br($row['dish_description']) . "</td>";***
echo "</tr>";
echo "<tr height='10px'>";
echo "<td style='width: 75px'></td>";
echo "<td style='width: 100px'></td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>