Strtoupper to cause Chinese garbled?

Source: Internet
Author: User
Strtoupper back cause Chinese garbled?
This post was last edited by Molaifeng on 2013-11-25 09:04:16

When deploying the project, encountered a strange problem, the page opened, the PHP script nested in the HTML page of the part garbled, the database is no problem. Later locate the problem that appears in this code (TP frame).


/**
* Get and set language definitions (case insensitive)
* @param string|array $name language variables
* @param string $value language value
* @return Mixed
*/
function L ($name =null, $value =null) {
Static $_lang = Array ();
Null parameter returns all definitions
if (empty ($name))
return $_lang;
Determining language Acquisition (or setting)
If it does not exist, return the full capital $name directly
if (is_string ($name)) {
echo $name, ';
$name = Strtoupper ($name); Echo $name;
if (Is_null ($value))
return Isset ($_lang[$name])? $_lang[$name]: $name;
$_lang[$name] = $value; Language definition
Return
}
Bulk definition
if (Is_array ($name))
$_lang = Array_merge ($_lang, Array_change_key_case ($name, case_upper));
Return
}




Later, the strtoupper should have become mb_strtoupper.

$name = Mb_strtoupper ($name, ' UTF-8 ');

This project is deployed in other servers when this problem does not appear ah, which is greatly explained under, thank you!!!

Share to:


------Solution--------------------
Strtoupper and Strtolower have had problems affecting Chinese in some previous versions of PHP.
But I've already corrected it.

I feel you have some problems with the use of this function.
Leaving the original context of the function, the function is simply to set some key-value pairs
Similar to defining constants
Like what
L (' x ', ' This is a problem ');
echo L (' X '); It's a question.
L (' x ', ' This is not a problem ');
echo L (' X '); It's not a problem.
echo L (' x '); It's not a problem.

Therefore, in general thinking, always use a simple combination of characters to correspond to complex character combinations (this is the abbreviation)

This function is used in TP to prompt the information of the multi-language conversion, so it is not likely to use Chinese to do the key
Once the program text appears in Chinese, then this program text in the execution of the possible garbled problem. Therefore, you should avoid the appearance of Chinese in the program text
That's the essence of the function.
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.