search
Homephp教程php手册php 判断编码

php 判断编码

Jun 06, 2016 pm 08:08 PM
cmdphpwinjudgmentcoding

最近在win的cmd下用 php 的 cli 调试程序总是出来乱码; 研究一番才知道原来是 cmd 只支持 gbk 的显示,如果 cli 吐出来的数据是 utf-8 编码的就出乱乱码,最后使用 mb_convert_encoding 转码, 在吐出来之前进行一次转码就可以了; 研究过程中看到一函数,

最近在win的cmd下用 php 的 cli 调试程序总是出来乱码;
研究一番才知道原来是 cmd 只支持 gbk 的显示,如果 cli 吐出来的数据是 utf-8 编码的就出乱乱码,最后使用 mb_convert_encoding 转码,
在吐出来之前进行一次转码就可以了;

研究过程中看到一函数,貌似精确度不能达到 100% 不过也不失为解决问题的一程序办法;

function is_utf8($word)
{
	if (preg_match("/^([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){1}$/",$word) == true || preg_match("/([".chr(228)."-".chr(233)."]{1}[".chr(128)."-".chr(191)."]{1}[".chr(128)."-".chr(191)."]{1}){2,}/",$word) == true)
	{
		return true;
	}
	else
	{
		return false;
	}
}
Statement
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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools