emediastudios Posted May 30, 2010 Share Posted May 30, 2010 Hi All, i want to show all the results from my services folder but want to limit the amount of characters displayed from the ".$a[content]." My current code works fine, just need to implement the limit on the content. I have a template setup that displays the entire content "view_service.php" $q = mysql_query("SELECT * FROM services ORDER BY id DESC"); while($a = mysql_fetch_array($q)){ echo "<table width='350' border='0' cellpadding='5' cellspacing='0' class='servicesbg'> <tr> <td width='80' rowspan='2' valign='top'><a href='view_service.php?id=".$a[id]."'><img src='".$a[img]."' alt='".$a[title]."' width='110' height='80' border='0'></a></td> <td width='250' valign='top'>".$a[title]."</td> </tr> <tr> <td valign='top'>".$a[content]."</td> </tr> </table><br>"; } Link to comment https://forums.phpfreaks.com/topic/203332-limit-string/ Share on other sites More sharing options...
andyhajime Posted May 30, 2010 Share Posted May 30, 2010 If you mean you want to limit the number of characters on the content, you can use my function. Enjoy. Usage: <td valign='top'>".TEXTCUT($a[content],"80")."</td> Function: function TEXTCUT($text, $words) { //<!-- code by iDexigns--!> $text = strip_tags($text); $matches= preg_split("/\s+/", $text, $words + 1); $sz = count($matches); if ($sz > $words) { unset($matches[$sz-1]); return implode(' ',$matches)."..."; } return $text; } Link to comment https://forums.phpfreaks.com/topic/203332-limit-string/#findComment-1065276 Share on other sites More sharing options...
trq Posted May 30, 2010 Share Posted May 30, 2010 See substr and the user submitted examples. Link to comment https://forums.phpfreaks.com/topic/203332-limit-string/#findComment-1065278 Share on other sites More sharing options...
emediastudios Posted May 30, 2010 Author Share Posted May 30, 2010 Quote See substr and the user submitted examples. andyhajime You the man! Thanks! Link to comment https://forums.phpfreaks.com/topic/203332-limit-string/#findComment-1065282 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.