Limit amount of text shown

23 posts by 6 authors in: Forums > CMS Builder
Last Post: November 17, 2010   (RSS)

Re: [zick] Limit amount of text shown

By Chris - November 17, 2010

Hi zick,

How about converting your <li></li> to <p></p> and making sure there's a space inserted in place of your <br/>?

function maxWords($html, $maxWords) {
$html = str_replace("<li>","<p>",$html);
$html = str_replace("</li>","</p>",$html);
$html = str_replace("<p>","*P*",$html);
$html = str_replace("</p>","*/P*",$html);
$html = str_replace("<"," <",$html);
$text = strip_tags($html);
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);
$output=str_replace("*P*","<p>",$output);
$output=str_replace("*/P*","</p>",$output);
$output.="</p>";

return $output;
}


Does that help?
All the best,
Chris

Re: [chris] Limit amount of text shown

By Mikey - November 17, 2010

Works great Chris!!! Thanks for the help!
Zick