CodeIgniter Forums
Word_limiter word count - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: Word_limiter word count (/thread-77023.html)



Word_limiter word count - stlake2011 - 07-12-2020

Good evening all. 

Quick question and observation.

Observation:
I am using word_limiter in a news posting app I am developing, and I noticed one thing. When I implement the limiter in a view, say 25 words, when I look at it (and yes actually counted for myself) I am usually only getting 12-15 words where I expect to see 25 words then the ellipses.

Note I am using Lorem Ipsum Generated dummy text so I know there is a lot more words then 25 in the paragraph(s) that I am passing through the function.

Question is:
Does the limiter count embedded HTML and is that why the actual printed words are only coming out at 50-60% what I would expect to see?


RE: Word_limiter word count - marcogmonteiro - 07-13-2020

That's really odd, must be something fishy with the string you're using. Can you do a dd() of said string and put it here?


RE: Word_limiter word count - stlake2011 - 07-13-2020

(07-13-2020, 01:21 AM)marcogmonteiro Wrote: That's really odd, must be something fishy with the string you're using. Can you do a dd() of said string and put it here?

Good Morning,

Full String:
Code:
$str = "<p><span style=\"font-family: 'Open Sans', Arial, sans-serif; font-size: 14px; text-align: justify; background-color: #ffffff;\">It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).</span></p>";

Output of dd():
Code:
$str string (751) "<p><span style="font-family: 'Open Sans', Arial, sans-serif; font-size: 14px...

Output of word_limiter:
PHP Code:
echo word_limiter($str,25);
It is a long established fact that a reader will be distracted by the… 

It does appear to count the words in the HTML as part of the string.
I tried the same string, stripped of html, in a second run (not shown for brevity but can be posted if needed), the string was smaller obviously (613) and the word_limiter showed the full first 25 words.
 
For my purposes, its not a deal breaker by any stretch since I am the only one going to be using this app I am developing, and will know this limitation. But it should be noted somewhere for others, that HTML text will be counted as part of the string alongside the "clean" text that's used as an example in the docs for this function.