When do I need to enable mbstring in PHP?

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

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

EDIT:

<?php echo "เคญ"; $s = strlen("เคญ"); echo $s; ?> 

How to make the second line of code work?

PS: I changed the default PHP encoding to UTF-8.

+4
source share
1 answer
  • You need mb_ string functions instead of regular string functions, for example. mb_substr instead of substr . If you do not use regular string functions, there is nothing to use for mb_ functions.
  • If you just pass text and PHP does nothing with that text, there is no need for mb_ functions.
  • For the mb_ functions mb_ work correctly, you will need to tell them what the encoding of your text is. They support many different encodings, without telling them that you are using their results, will be incorrect. You can pass this encoding to every call to the mb_ function, for example. mb_strlen($str, 'UTF-8') , or you can set it once for all mb_ with mb_internal_encoding('UTF-8') .

See What every programmer absolutely needs to know positively about encodings and character sets for working with text for a comprehensive introduction.

+2
source

Source: https://habr.com/ru/post/1445010/


All Articles