Home Backend Development PHP Tutorial php 数组键名 能是中文, 哪位高手用过,会不会出现后患.

php 数组键名 能是中文, 哪位高手用过,会不会出现后患.

Jun 13, 2016 am 11:10 AM
gbk hash key nbsp php

php 数组键名 能是中文, 谁用过,会不会出现后患...
RT 中文键名会不会留下后患>


------解决方案--------------------
可以用,没有问题
------解决方案--------------------
php的数组键名会被php内部转换为一个hash key。理论上没有问题。但中文总是会引起很多奇怪的bug。比如gbk下的低字节5c问题。

还有不同字符集下,php内部识别的unicode会不一致。我猜想,但没有实践过:

假如你的a.php使用了gbk编码,代码中声明了一个$a['中文']='123'的中文key数组。
b.php引用了a.php。但b.php文件本身的编码是utf-8。然后在b.php中echo $a['中文']。
此时,两个文件中的'中文'俩字在php内部所转换的hash key可能是不一致的,那么会造成b.php中的$a['中文']取不到任何值。

所以最好不要用中文。
------解决方案--------------------
呵呵,有一种扰码工具恰恰就是利用了这一点,让你无法破解
------解决方案--------------------
试一下这几个字(限GBK):榎 梶 東

如果这几个字没问题就全部没问题了…… 
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

CakePHP Date and Time

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

CakePHP Project Configuration

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

CakePHP File upload

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

CakePHP Routing

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

Discuss CakePHP

Unpatchable Yubico two-factor authentication key vulnerability breaks the security of most Yubikey 5, Security Key, and YubiHSM 2FA devices Unpatchable Yubico two-factor authentication key vulnerability breaks the security of most Yubikey 5, Security Key, and YubiHSM 2FA devices Sep 04, 2024 pm 06:32 PM

Unpatchable Yubico two-factor authentication key vulnerability breaks the security of most Yubikey 5, Security Key, and YubiHSM 2FA devices

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP Quick Guide

See all articles