Get the App
SLTechnology News&Howtos  ›  Development  › 

How to intercept the first Chinese garbled code by php

Shulou Source: shulou.com Published: 2022-06-02 08:56:03 10月02日 Update

This article mainly explains "how php intercepts the first Chinese garbled code," the explanation content in the article is simple and clear, easy to learn and understand, please follow the ideas of Xiaobian slowly in-depth, together to study and learn "how php intercepts the first Chinese garbled code" bar!

php intercepts the first Chinese garbled code solution: 1, create a PHP sample file;2, set "charset= utf-8" encoding;3, by "function str($str ='',$len=0){...} "The method can be intercepted.

Operating environment: Windows 7, PHP 7.4, DELL G3

Php how to intercept the first Chinese garbled code?

php solves Chinese interception garbled code problem

in view of intercept that character string to appear Chinese garbled code question, on the net has many introduction, also has many functions, but the author looked at the net function, always felt that somewhat awkward,

So I wrote a function to prevent Chinese garbled characters from intercepting strings.

The principle of implementation is still relatively simple, mainly using ASCII encoding and Chinese encoding binary range is not consistent to distinguish them, and then, through substr() intercept string function to achieve.

Here is the code I wrote, note: I am only here for utf-8 coding, other coding, the viewer can manually change the function to support other coding.

Tags: Chinese character string garbled coding function number question learning content ellipsis article length utf-8 consistency awkwardness success binary code method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Docker vpn OPPO Reno NVidia