how to get actual number of unicode character?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
markthien
Forum Commoner
Posts: 33
Joined: Fri Feb 13, 2009 7:50 pm

how to get actual number of unicode character?

Post by markthien »

Hi guys,

I got a textarea let user enter their remark and I need to get the length of user entered remark.
Hence, I use strlen but it's no right when user enter both chinese and alphabet together like:

$tmp = 'Hello dear'; // string from textarea
$len = strlen($tmp); // this is correct where it return 10

$tmp = 'Hello dear 双皮奶'; // string from textarea
$len = strlen($tmp); // this is not really correct where it return 19

I need it to return length of 13 for the 2nd one. Hwo to do that? thanks!

Cheers,
Mark Thien
Post Reply