Does strtoupper cause Chinese garbled characters?-php Tutorial

Source: Internet
Author: User
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 ). Does the strtoupper return cause 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.

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.