working character limiter |
[eluser]ommy[/eluser]
Hi there, I just noticed an error in the character_limiter (text helper). At first i thought i made an error when calling the helper, but it seemed (and was confirmed by the forum) that the helper was faulty. 1.7 also has a problem with this helper. Don't really know why the helper is quite massive in codeigniter, i added a much simpler version to mine temporarely. Code: function character_limiter($str, $n = 500, $end_char = '…') If you have advice on solving this problem or information about why this helper has about 4 if functions, let me know ![]() Greets!
[eluser]Derek Jones[/eluser]
http://ellislab.com/codeigniter/user-gui...elper.html Quote:It maintains the integrity of words so the character count may be slightly more or less then what you specify The helper's a bit smarter than a simple substr(). Perhaps if you can elaborate on what the problem is that needs to be solved - you make reference to it a few times but don't ever mention what it is?
[eluser]ommy[/eluser]
That clears up a few things. What happens is that the character limiter only limits the text if spaces occur. So basically it behaves as a word limiter works great with the right user input, but i heard someone say: never trust user input ![]() thanks for the lightning fast reply!
[eluser]Derek Jones[/eluser]
Right, if there aren't any spaces, it will consider it as one long "word". If you're looking for a strict "has to be X characters and no more", the substr() is the way to go. This helper tries to consider the context it would be used in, cutting someone's speech to as close to X characters as it can without leaving any partial words.
[eluser]ommy[/eluser]
so basically this is a little more what i would expect in a character_limiter: Code: function character_limiter($str, $n = 500, $end_char = '…')
[eluser]Derek Jones[/eluser]
Changes the context and behavior a bit from the way the function is described, but if those are what your needs are, that's perfectly legitimate. Were I in your shoes, I'd simply extend the Text Helper to use your customized version of the function.
[eluser]mercy loving criminal[/eluser]
The character_limiter function also seems to break encoding of the 'à' character. I've reverted to using word_limiter instead to achieve what I wanted, but would be good to see a formal fix to this - unless I've missed something. |
Welcome Guest, Not a member yet? Register Sign In |