Welcome Guest, Not a member yet? Register   Sign In
character_limiter not working?
#1

[eluser]Unknown[/eluser]
Hello,

I have encountered the following behaviour while using the character_limiter function (CI 1.7.2):

It seems that if there are no spaces inside a long string, the function simply returns the whole string without truncating it at all.

Here is an example where the function works as expected:

Code:
$string="Lorem ipsum dolor sit amet consectetur adipiscing elit Sed et nibh eget est dapibus rhoncus eu sed metus In hac habitasse platea dictumst Aenean et lacus nibh";          
echo character_limiter($string,10);

In the example above it returns "Lorem ipsum…" which is correct.

But in the example bellow it returns the whole string no matter how many characters i specify in the function's second parameter:

Code:
$string="LoremipsumdolorsitametconsecteturadipiscingelitSedetnibhegetestdapibusrhoncuseusedmetusInhachabitasseplateadictumstAeneanetlacusnibh";          
echo character_limiter($string,10);

Did anyone else encountered this issue?
#2

[eluser]davidbehler[/eluser]
From the Guide
Quote:..It maintains the integrity of words so the character count may be slightly more or less then what you specify...

This means that the behaviour in your second example is perfectly normal because your string basically is one huge word which this function won't break.

You might want to use
Code:
echo substr($string, 10).'...';
instead.




Theme © iAndrew 2016 - Forum software by © MyBB