


PHP utf-8 Chinese interception without garbled characters (string judgment version)
/*E4 B8 AD E5 9B BD 中国 1110 0100 10111000 10101101 1110 0101 1001101110111101 61 a 0011 1101 0xxx xxxx ,1个字节 110xx xxxx , 2个字节 1110 xxxx, 3 1111 0xxxx 4... */<pre name="code" class="php">$str = '中华人aaa民共b和国,c万岁'; function utf8sub($str,$len){ if($len <=0) return ''; $length = strlen($str); $offset=0; $chars=0; $res=''; while($chars<$len && $offset<$length){ $heigh = decbin(ord(substr($str, $offset,1))); echo $heigh ,'</br>'; if(strlen($heigh)<8){ $count=1; }else if(substr($heigh,0,3) == '110'){ $count=2; }else if(substr($heigh,0,4) == '1110'){ $count=3; }else if(substr($heigh,0,5) == '11110'){ $count=4; }else if(substr($heigh,0,6) == '111110'){ $count=5; }else if(substr($heigh,0,7) == '1111110'){ $count=6; } $res .= substr($str, $offset,$count); $chars += 1; $offset += $count; } return $res; } echo utf8sub($str,10);
The above introduces PHP utf-8 Chinese interception without garbled characters (string judgment version), including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics

The Count function is used to count the number of numbers in a specified range. It ignores text, logical values, and null values, but counts empty cells. The Count function only counts the number of cells that contain actual numbers. The CountA function is used to count the number of non-empty cells in a specified range. It not only counts cells containing actual numbers, but also counts the number of non-empty cells containing text, logical values, and formulas.

This article will explain in detail the ASCII value of the first character of the string returned by PHP. The editor thinks it is very practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP returns the ASCII value of the first character of a string Introduction In PHP, getting the ASCII value of the first character of a string is a common operation that involves basic knowledge of string processing and character encoding. ASCII values are used to represent the numeric value of characters in computer systems and are critical for character comparison, data transmission and storage. The process of getting the ASCII value of the first character of a string involves the following steps: Get String: Determine the string for which you want to get the ASCII value. It can be a variable or a string constant

This article will explain in detail how PHP returns the string from the start position to the end position of a string in another string. The editor thinks it is quite practical, so I share it with you as a reference. I hope you will finish reading this article. You can gain something from this article. Use the substr() function in PHP to extract substrings from a string. The substr() function can extract characters within a specified range from a string. The syntax is as follows: substr(string,start,length) where: string: the original string from which the substring is to be extracted. start: The index of the starting position of the substring (starting from 0). length (optional): The length of the substring. If not specified, then

This article introduces to you the usage differences of MySQL’s Count function. The need for statistical data is very easy to encounter in our daily development. MySQL also supports a variety of calculation functions. Next, let’s take a look at the differences between them. , and whether they have some pitfalls.

Understand the substr() function in PHP for intercepting strings. In the PHP language, the substr() function is a very useful string processing function, which can be used to intercept string fragments at a specified position and length. The substr() function accepts three parameters: the string to be intercepted, the starting position of the interception, and the length of the interception. Below we will introduce the use of the substr() function in detail and give specific code examples. Basic usage of substr() function substr() function

PHPNotice:Undefinedoffset is a common PHP program error. It means that the program attempts to use a subscript that does not exist in the array, causing the program to fail to run normally. This error usually occurs when the PHP interpreter displays the following warning message: Notice: Undefinedoffset. Here are some ways to resolve the PHPNotice:Undefinedoffset error: Check the code First, it should

The usage of the count function in PHP is: [count(array,mode);], where the parameter array specifies the array to be counted, and the parameter mode specifies the mode of the function.

Note 1. Count is a terminal operation that can count the total number of elements in the stream. The return value is of long type. 2. count() returns the count of elements in the stream. This is a special case of induction (an induction operation takes a sequence of input elements and combines them into a summary result by repeatedly applying the combining operation). This is a terminal operation and may have consequences and side effects. After a terminal operation is performed, the pipe is considered consumed and cannot be reused. Example // Verify whether there is a string in the list starting with a, and match the first one, that is, return truebooleananyStartsWithA=stringCollection.stream().anyMatch((s
