最近在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; } }
原文地址:php 判断编码, 感谢原作者分享。

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver CS6
Visual web development tools

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

WebStorm Mac version
Useful JavaScript development tools
