Question

mbstring extension provides enhanced support for Simplified Chinese, Traditional Chinese, Korean, and Russian in addition to Japanese.

I tried displaying a Japanese character (which I copied from www.google.co.jp) on my PHP page and it displayed fine. Do I need to use mbstring when I'm displaying UTF-32 characters?

EDIT:

<?php
    echo "भ";                  
    $s = strlen("भ");
    echo $s;
?>

How do I make the second line of code to work?

PS: I have changed PHP default charset to UTF-8.

Was it helpful?

Solution

  • You need the mb_ string functions in place of the regular string functions, e.g. mb_substr instead of substr. If you don't use the regular string functions, there's no use for the mb_ functions either.
  • If you're just passing text through and PHP isn't doing anything with that text, there's no need for the mb_ functions.
  • To make the mb_ functions work correctly, you'll have to tell them what encoding your text is in. They support many different encodings, without telling them which you're using their results will be incorrect. You can pass that encoding to each mb_ function call, e.g. mb_strlen($str, 'UTF-8'), or you can set it once for all mb_ functions using mb_internal_encoding('UTF-8').

See What Every Programmer Absolutely, Positively Needs To Know About Encodings And Character Sets To Work With Text for a comprehensive introduction.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top