Dave,
I've tried two different maxWord options, but neither seem to be working 100% for me. I've tried to explain my problem below, can you shed some light on what I need to do to get maxWords working for me?
Using the code below works, up until there's a <br/> break or <ul><li> bullet list. In the wysiwyg if there's a <br/> break to start a new sentence directly below the first, the <br/> break is lost and the new sentence does not have a space after the period where the first sentence ended and the new sentence begins. Example (... this sentence has ended.This sentence has no space before previous sentence period.)
And when there's a <ul> <li> bullet list the text within the bullet list looses it's paragraph formatting completely and the font style does not match any of the other article's font style using maxWords.
I've attached a snap shot with the problem areas highlighted.
Code Option One:
<?PHP
// function maxWords($textOrHtml, $maxWords) {
// $text=str_replace("<p>","*P*",$textOrHtml);
// $text= str_replace("</p>","*/P*",$text);
// $text = strip_tags($text);
// $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;
// }
?>
So then I tried using the code below and that fixes the text font style formatting for <ul> <li> by eliminating it altogether and making it read as a sentence with the <p> paragraph style applied, But the problem I'm have with this is the if I have a <br/> break in the wysiwyg to start a new sentence directly below the previous sentence. The <br/> in the wysiwyg is lost and there's no space between the ending sentence's period and where the new sentence begins. Example (... this sentence has ended.This sentence has no space before previous sentence period.)
Code Option Two:
<?php
// Usage: < ?php print maxWords($content, 25); ? >
function maxWords($textOrHtml, $maxWords) {
$text = strip_tags($textOrHtml);
$words = preg_split("/\s+/", $text, $maxWords+1);
if (count($words) > $maxWords) { unset($words[$maxWords]); }
$output = join(' ', $words);
return $output;
}
?>
Has anyone else had this problem using maxWords and does anyone know of a fix to get this working?
Thanks, Zick