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 definition (case insensitive) * @param string|array $name language variable * @param string $value language value * @return mixed */function L ($name =nul L, $value =null) { static $_lang = Array (); The null parameter returns all definitions if (empty ($name)) return $_lang; Determine if the language gets (or sets) //If not present, return all uppercase $name 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 define 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!!!
Reply to discussion (solution)
The picture is not full
Whether it is caused by a browser encoding problem, check the file encoding.
No, the problem has been fixed, that's the code above.
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.
Thanks for the big answer!!!