Home > Backend Development > PHP Tutorial > 中文转换内码

中文转换内码

WBOY
Release: 2016-06-23 13:41:20
Original
1052 people have browsed it

中文是:  有限公司

转换好是:
\xe6\x9c\x89\xe9\x99\x90\xe5\x85\xac\xe5\x8f\xb8

请问PHP5里有现成的函数进行互转吗?

请告知和推荐方法
谢谢


回复讨论(解决方案)

核心函数库里我没有见过。自己组装了一下:

$s = '有限公司';$ens = '\x'. implode( '\x', str_split( bin2hex($s), 2) );var_dump($ens);
Copy after login

string(48) "\xe6\x9c\x89\xe9\x99\x90\xe5\x85\xac\xe5\x8f\xb8"

$s = '有限公司';
//$s = iconv('gbk', 'utf-8', $s);//你需要的是utf-8串的内码表示,gbk环境中需要这句
echo str_replace('%', '\x', urlencode($s));

非常感谢, 同时说声对不起, 长时间没有来登录忘记了结贴.

谢谢两位大叔 

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template