2

Sometimes I see some PHP scripts with the following lines at the beginning:

<?php
mb_language('uni');
mb_internal_encoding('UTF-8');

I know these two functions come from the mb_string PHP module. But what is the effective purpose of calling these two functions at the beginning of the script?

I read the docs, http://php.net/manual/en/function.mb-internal-encoding.php, a user says:

Especially when writing PHP scripts for use on different servers, it is a very good idea to explicitly set the internal encoding somewhere on top of every document served, e.g.

mb_internal_encoding("UTF-8");

This, in combination with mysql-statement "SET NAMES 'utf8'", will save a lot of debugging trouble.

Also, use the multi-byte string functions instead of the ones you may be used to, e.g. mb_strlen() instead of strlen(), etc.

But how much should I worry about the encoding of: DB connection (I use the UTF-8 charset for my tables and call SET NAMES utf8; as soon as I connect to the database), HTTP request input values and output (especially when dealing with multibyte characters like those in the Japanese language), email sending, regular expression patterns to search text, etc... when writing an i18n PHP application and how do these mb_* functions really help me?

I also read this post PHP string functions vs mbstring functions and as I understand it the user who answers the question says that mb_* functions should be avoided:

a simple replacement of the 8-bit string functions with their mb_* counterparts will cause nothing but trouble.

Thank you for your attention. Insights and clarifications are welcome.

Community
  • 1
  • 1
tonix
  • 6,671
  • 13
  • 75
  • 136

1 Answers1

0

Used for encoding e-mail messages. Valid languages are "Japanese", "ja","English","en" and "uni" (UTF-8). mb_send_mail() uses this setting to encode e-mail.

Copied from http://php.net/manual/en/function.mb-language.php

Salman
  • 58
  • 9