utf-8 character count help |
[eluser]Bahodir[/eluser]
Hi, Is there a build-in function for counting utf8-characters? I want to limit long lines to specific length using character_limiter(), but PHP is not giving me the proper lengths of a string. For example, the following code should output 'при...', but its echoing 'привет...' Code: <?php Any help would be awesome.
[eluser]Bahodir[/eluser]
pistolPete, thank you for your help. This code you gave me correctly counts the number of characters. Code: mb_strlen($string,'UTF-8'); But how do I trim my string using character_limiter()? I tried this Code: $str = "привет"; And, i think it is giving me the correct length, except the decoded characters show up as ????... Now how can I show the correct characters?
[eluser]Bahodir[/eluser]
[quote author="pistolPete" date="1235886037"]What's your php internal encoding setting? [/quote] Oh, I think it is utf-8
[eluser]pistolPete[/eluser]
[quote author="Bahodir" date="1235891451"]Oh, I think it is utf-8[/quote] You can check it using this function: Code: /* Display current internal character encoding */ I modified the helper to work with utf8 strings: Code: function character_limiter($str, $n = 500, $end_char = '…') Have a look at "Extending" Helpers.
[eluser]Bahodir[/eluser]
thank you once more, i haven't checked it yet, but i hope it works |
Welcome Guest, Not a member yet? Register Sign In |