phpnewbie112 Posted December 15, 2008 Share Posted December 15, 2008 Hello I usually use strlen($text) to count the total characters of a text but how can I do it with unicode text? I tried it but it is returning false values. Quote Link to comment https://forums.phpfreaks.com/topic/137101-strlen-and-unicode/ Share on other sites More sharing options...
premiso Posted December 15, 2008 Share Posted December 15, 2008 <?php function ustrlen($s) { $a = preg_split("//u", $s); $i = -2; foreach ($a as $b) $i++; return $i; } ?> Found on the first user comment at strlen manual. Quote Link to comment https://forums.phpfreaks.com/topic/137101-strlen-and-unicode/#findComment-716091 Share on other sites More sharing options...
Mchl Posted December 15, 2008 Share Posted December 15, 2008 mb_strlen for multibyte safe strlen() Quote Link to comment https://forums.phpfreaks.com/topic/137101-strlen-and-unicode/#findComment-716095 Share on other sites More sharing options...
phpnewbie112 Posted December 15, 2008 Author Share Posted December 15, 2008 premiso I already tried it but did not work Quote Link to comment https://forums.phpfreaks.com/topic/137101-strlen-and-unicode/#findComment-716103 Share on other sites More sharing options...
Maq Posted December 15, 2008 Share Posted December 15, 2008 I think you need to use html_entities_decode() Quote Link to comment https://forums.phpfreaks.com/topic/137101-strlen-and-unicode/#findComment-716104 Share on other sites More sharing options...
phpnewbie112 Posted December 16, 2008 Author Share Posted December 16, 2008 unfortunately none of them is returning the correct count Quote Link to comment https://forums.phpfreaks.com/topic/137101-strlen-and-unicode/#findComment-716469 Share on other sites More sharing options...
Mchl Posted December 16, 2008 Share Posted December 16, 2008 Did you try mb_string functions? Quote Link to comment https://forums.phpfreaks.com/topic/137101-strlen-and-unicode/#findComment-716791 Share on other sites More sharing options...
Maq Posted December 16, 2008 Share Posted December 16, 2008 strlen(html_entity_decode($string)); Quote Link to comment https://forums.phpfreaks.com/topic/137101-strlen-and-unicode/#findComment-716797 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.