Jump to content

Limit String


emediastudios

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.