简体   繁体   English

PHP MYSQL 自动换行

[英]PHP MYSQL Word Wrap

I am new on PHP, i am wondering where can i insert / use the wordwrap code in my existing code.我是 PHP 的新手,我想知道在我现有的代码中哪里可以插入/使用自动换行代码。 My objective is to apply word wrap to the Brand description data: Below are the details:我的目标是将自动换行应用于品牌描述数据:以下是详细信息:

This is a part of my existing code that displays the data from MYSQL into an HTML table:这是我现有代码的一部分,它将 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>";
}

I want to apply a word wrap to the brand description field and i do not know how to do it.我想对品牌描述字段应用自动换行,但我不知道该怎么做。 Hope you can help希望你能帮忙

use native function of使用原生 function 的

http://php.net/manual/en/function.wordwrap.php 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>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM