The strtoupper reply causes Chinese garbled text. This post was last edited by molaifeng from 2013-11-2509: 04: 16 & nbsp; during project deployment, A strange problem occurs. after the page is opened, the php script embedded in the html page is garbled and the database is okay. Later, the problem was found in the code section (tp framework ). ** & Strtoupper leading to Chinese garbled characters
This post was last edited by molaifeng at 09:04:16, January 25 ,.
During Project deployment, a strange problem occurs. after the page is opened, php scripts embedded in the html page are garbled and the database is okay. Later, the problem was found in the code section (tp framework ).
/**
* Get and set language definitions (case insensitive)
* @ Param string | array $ name language variable
* @ Param string $ value language value
* @ Return mixed
*/
Function L ($ name = null, $ value = null ){
Static $ _ lang = array ();
// Null parameters return all definitions
If (empty ($ name ))
Return $ _ lang;
// Obtain (or set) the judgment language)
// If it does not exist, all uppercase $ names are returned 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;
}
// Batch definition
If (is_array ($ name ))
$ _ Lang = array_merge ($ _ lang, array_change_key_case ($ name, CASE_UPPER ));
Return;
}
Later, the strtoupper was converted into mb_strtoupper.
$name = mb_strtoupper($name, 'UTF-8');
This problem does not occur when this project is deployed on other servers. Which of the following statements can be explained? thank you !!!
Share:
------ Solution --------------------
Strtoupper and strtolower have encountered problems affecting Chinese characters in some previous php versions.
But it has already been corrected.
I feel that you have some problems with this function.
In the original context of this function, this function only sets some key-value pairs.
Similar to defining constants
For example
L ('X', 'This is a problem ');
Echo L ('x'); // This is a problem
L ('X', 'this is not a problem ');
Echo L ('x'); // This is not a problem
Echo L ('x'); // This is not a problem
Therefore, in general thinking, simple character combinations are always used to correspond to complex character combinations (this is the acronyms)
This function is used in TP to prompt the multilingual conversion of information, so it is unlikely to use Chinese as a key.
Once the program text contains Chinese characters, garbled characters may occur during execution. Therefore, avoid Chinese characters in the program text.
This is the essence of this function.