在部署项目时,遇到一个奇怪的问题,页面打开后,php脚本嵌套在html页面里的部分出现乱码,数据库是没问题的。后来定位,发现问题出现在这段代码上(tp框架)。
/** * 获取和设置语言定义(不区分大小写) * @param string|array $name 语言变量 * @param string $value 语言值 * @return mixed */function L($name=null, $value=null) { static $_lang = array(); // 空参数返回所有定义 if (empty($name)) return $_lang; // 判断语言获取(或设置) // 若不存在,直接返回全大写$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; // 语言定义 return; } // 批量定义 if (is_array($name)) $_lang = array_merge($_lang, array_change_key_case($name, CASE_UPPER)); return;}
后来,把那个strtoupper该成了mb_strtoupper
$name = mb_strtoupper($name, 'UTF-8');
这个项目部署在其他服务器时没出现这个问题啊,哪位大大解释下,谢谢!!!
回复讨论(解决方案)
图没发全
是否是浏览器编码问题造成,检查下文件编码。
不是,问题已经定位了,就是上面的那个代码
strtoupper、strtolower 在以前某些 php 版本中曾出现过对中文产生影响的问题
但早已经纠正过了
感觉你对这个函数的使用存在一些问题
离开这个函数原来的语境,这个函数只不过是设置一些键值对
和定义常量相似
比如
L('x', '这是个问题');
echo L('X'); // 这是个问题
L('x', '这不是个问题');
echo L('X'); //这不是个问题
echo L('x'); //这不是个问题
因此,在一般思维中,总是用简单的字符组合去对应复杂的字符组合(这就是缩略词)
这个函数在 TP 中是用于提示信息的多语言转换的,所以也不大可能用中文做键
一旦程序文本中出现中文,那么这个程序文本在执行时就有可能出现乱码问题。所以应避免在程序文本中出现中文
这就是这个函数的精髓所在
谢谢大大的回答!!!

The article discusses PHP, detailing its full form, main uses in web development, comparison with Python and Java, and its ease of learning for beginners.

PHP handles form data using $\_POST and $\_GET superglobals, with security ensured through validation, sanitization, and secure database interactions.

The article compares PHP and ASP.NET, focusing on their suitability for large-scale web applications, performance differences, and security features. Both are viable for large projects, but PHP is open-source and platform-independent, while ASP.NET,

PHP's case sensitivity varies: functions are insensitive, while variables and classes are sensitive. Best practices include consistent naming and using case-insensitive functions for comparisons.

The article discusses various methods for page redirection in PHP, focusing on the header() function and addressing common issues like "headers already sent" errors.

Article discusses type hinting in PHP, a feature for specifying expected data types in functions. Main issue is improving code quality and readability through type enforcement.

The article discusses PHP Data Objects (PDO), an extension for database access in PHP. It highlights PDO's role in enhancing security through prepared statements and its benefits over MySQLi, including database abstraction and better error handling.

Article discusses creating and securing PHP APIs, detailing steps from endpoint definition to performance optimization using frameworks like Laravel and best security practices.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version
Chinese version, very easy to use

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Mac version
God-level code editing software (SublimeText3)
