You can do this in a simple way:
echo substr($row['title'],0,26).'...'; ?>
With method:
function limitChars($text, $limit=20)
{
return substr($text, $limit).'...';
}
echo limitChars($row['title'], 26);
Or, with method without breaking words; consider that every string in PHP is an array, just break it in the spaces:
function limitChars($text, $limit=4)
{
$join = array();
$ArrayString = explode(" ", $text);
if ($limit > count($ArrayString)) {
$limit = count($ArrayString) / 2;
}
foreach ($ArrayString as $key => $word) {
$join[] = $word;
if ($key == $limit) {
break;
}
}
//print_r($join);
return implode(" ", $join)."...";
}
echo limitChars($row['title'], 3);