gpt4 book ai didi

PHP MYSQL 自动换行

转载 作者:行者123 更新时间:2023-11-29 14:45:40 24 4
gpt4 key购买 nike

我是 PHP 新手,我想知道在现有代码中哪里可以插入/使用自动换行代码。我的目标是将自动换行应用于品牌描述数据:以下是详细信息:

这是我现有代码的一部分,它将 MYSQL 中的数据显示到 HTML 表中:

$data = mysql_query("SELECT * from web_brands");
//Display table headers
print ("<table border='1' ALIGN = 'CENTER'
width='800'><tr><th>ID</th><th>LOGO</th><th>BRANDNAME</th><th>DESCRIPTION</th><th>SHORTNAME </th></tr>");

while($row = mysql_fetch_array($data)){ //Display the results in different cells
echo "<tr>";
echo '<td>' .$row['brand_id'] . '</td>';
echo "<td>" . "<img width=300px height=200px src=../brandslogo/" . $row ['logo'].">" . "</td>";
echo "<td>" . $row['brand_name'] . "</td>";
echo '<td width="300">' . $row['brand_description'] . "</td>";
echo "<td>" . $row['brand_shortname'] . "</td>";
echo "</tr>";
}

我想在品牌描述字段中应用自动换行,但我不知道该怎么做。希望您能帮忙

最佳答案

使用原生函数

http://php.net/manual/en/function.wordwrap.php

//change this
echo "<td>" . $row['brand_name'] . "</td>";
//to , this will wrap for each 20 width
echo "<td>" . wordwrap($row['brand_description'], 20, "<br />\n") . "</td>";

关于PHP MYSQL 自动换行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7004867/

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