Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.