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. 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. 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() 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 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() 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 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? 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)); Link to comment https://forums.phpfreaks.com/topic/137101-strlen-and-unicode/#findComment-716797 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.