使用 echo 显示 table 的前 100 个字符
Display first 100 characters from the table using echo
下午,
天气真好,不是吗?无论如何..
这是我的问题:(见图)http://prntscr.com/7drmc5
当然这对用户来说不是很友好,我试图只显示字段的前 100 个字符,中间有一个中断。
这是我的代码:
echo '<tbody>
<tr class="server glossed site">
<td class="rank hidden-sm hidden-xs">
'.$rank.'</td>
<td class="description"><p><a href="out.php?id='.$row['id'].'" target="_blank">'.$row['name'].'<br /><p><a href="out.php?id='.$row['id'].'" target="_blank"><img src="'.$row['banner'].'" width="470" height="60"></a></p></a><br><p class="hidden-sm hidden-xs">'.
$row['description'].'</p></td>
<td class="votes hidden-sm hidden-xs">'.$row['votes'].'</td>
</tr>
';
感谢任何试过这个的人!
你可以利用substr and you can also wrap it using wordwrap
//it would wrap your text upto 20 characters
$wrappedText = wordwrap(substr($row['description'], 0, 100), 20, "<br />\n", true);
echo '<tbody>
<tr class="server glossed site">
<td class="rank hidden-sm hidden-xs">
'.$rank.'</td>
<td class="description"><p><a href="out.php?id='.$row['id'].'" target="_blank">'.$row['name'].'<br /><p><a href="out.php?id='.$row['id'].'" target="_blank"><img src="'.$row['banner'].'" width="470" height="60"></a></p></a><br><p class="hidden-sm hidden-xs">'.
$wrappedText.'</p></td>
<td class="votes hidden-sm hidden-xs">'.$row['votes'].'</td>
</tr>
';
使用substr();
$result = substr($myStr, 0, 100);//it will dispaly to firdt 100 charector from string
在代码代码中它将实现为
<td class="description"><p><a href="out.php?id='.$row['id'].'" target="_blank">'.$row['name'].'<br /><p><a href="out.php?id='.$row['id'].'" target="_blank"><img src="'.$row['banner'].'" width="470" height="60"></a></p></a><br><p class="hidden-sm hidden-xs">'.
substr($row['description'],0,100).'</p></td>
根据您的情况使用
wordwrap($row['description'], 100, "\n", true);
下午,
天气真好,不是吗?无论如何..
这是我的问题:(见图)http://prntscr.com/7drmc5
当然这对用户来说不是很友好,我试图只显示字段的前 100 个字符,中间有一个中断。
这是我的代码:
echo '<tbody>
<tr class="server glossed site">
<td class="rank hidden-sm hidden-xs">
'.$rank.'</td>
<td class="description"><p><a href="out.php?id='.$row['id'].'" target="_blank">'.$row['name'].'<br /><p><a href="out.php?id='.$row['id'].'" target="_blank"><img src="'.$row['banner'].'" width="470" height="60"></a></p></a><br><p class="hidden-sm hidden-xs">'.
$row['description'].'</p></td>
<td class="votes hidden-sm hidden-xs">'.$row['votes'].'</td>
</tr>
';
感谢任何试过这个的人!
你可以利用substr and you can also wrap it using wordwrap
//it would wrap your text upto 20 characters
$wrappedText = wordwrap(substr($row['description'], 0, 100), 20, "<br />\n", true);
echo '<tbody>
<tr class="server glossed site">
<td class="rank hidden-sm hidden-xs">
'.$rank.'</td>
<td class="description"><p><a href="out.php?id='.$row['id'].'" target="_blank">'.$row['name'].'<br /><p><a href="out.php?id='.$row['id'].'" target="_blank"><img src="'.$row['banner'].'" width="470" height="60"></a></p></a><br><p class="hidden-sm hidden-xs">'.
$wrappedText.'</p></td>
<td class="votes hidden-sm hidden-xs">'.$row['votes'].'</td>
</tr>
';
使用substr();
$result = substr($myStr, 0, 100);//it will dispaly to firdt 100 charector from string
在代码代码中它将实现为
<td class="description"><p><a href="out.php?id='.$row['id'].'" target="_blank">'.$row['name'].'<br /><p><a href="out.php?id='.$row['id'].'" target="_blank"><img src="'.$row['banner'].'" width="470" height="60"></a></p></a><br><p class="hidden-sm hidden-xs">'.
substr($row['description'],0,100).'</p></td>
根据您的情况使用
wordwrap($row['description'], 100, "\n", true);