


Use regular rules to intercept a fixed-length string from the source string from the specified starting position_PHP tutorial
[Code] Use regular rules to intercept a fixed-length string (including Chinese) from the source string from the specified starting position [Fourth Edition]
[Code] Use regular rules to intercept a string of a certain length from the source string starting from the specified starting position [Fourth Edition]
[Code] Use regular expressions to intercept a string of a certain length from the source string starting from the specified starting position [Fourth revision]
[Code] Use regular expressions to intercept a string of a certain byte length from the source string starting from the head of the string
[Code] Use regular expressions to intercept a string of a certain length from the source string starting from the specified starting position
(BTW: Chinese encoding is very complex and somewhat unreasonable. The high bits are 0xa1-0xfe (excluding 0xff because 0xff, which is 255, plays an important role in the telnet protocol), and the low bits are 0x40-0xfe; and GBK has extended the high bits to unicode mapping. 0x81-0xfe
Explanation on whether the last byte is intercepted in wrong Chinese:
The last byte, if half of the Chinese text is intercepted, should be the high-order byte, and its ASCII code is greater than 0x81.
Because the high-order bytes of Chinese are greater than 0x81, but the low-order bytes are not limited.
A complete Chinese character: [0x81-0xfe][0x40-0xfe]
Therefore, regular expressions are used to extract Chinese characters and non-Chinese characters in sequence, with Chinese characters taking priority.
The last byte, if half of the Chinese character is intercepted, then it will be a non-Chinese character, and it will be the high-order byte of the Chinese character
And determine whether this byte is in [0x81-0xfe], you can know whether the interception is wrong.
//------------------------------------------------ ---------------
// File name: preg_substr.php
// Description: Use regular expressions to intercept a certain amount of string from the source string starting from the specified starting position
//------------------------------------------------ ----------
/// Function description
/// Function name: preg_substr
/// Function version: Fourth revision
/// Function: Use regular expressions to intercept a certain amount of string from the source string starting from the specified starting position
/// Function parameters:
/// $strSource : source string
/// $intStart: starting position, the default is 0, which means starting from the beginning
/// $intLen: intercept length, default is 32
function preg_substr($strSource, $intStart=0, $intLen=32)
{
is_int($intLen) ?0:die("len isn't an integer");
is_int($intStart) ?0:die("start isn't an integer");
if ($intStart>=0 && $intLen>0 && @preg_match('/^(.{'.$intStart.'})(.{0,'.$intLen.'})/si', $strSource) ) {
@preg_match('/^(.{'.$intStart.'})(.{0,'.$intLen.'})/si', $strSource, $regs);
@preg_match_all('/([x81-xFE].|.)/sim', $regs[1], $regs1, PREG_PATTERN_ORDER);
@preg_match('/^[x81-xFE]$/',$regs1[1][count($regs1[1])-1])?$intStart--:0;
@preg_match('/^(.{'.$intStart.'})(.{0,'.$intLen.'})/si', $strSource, $regs);
@preg_match_all('/([x81-xFE].|.)/sim', $regs[2], $regs1, PREG_PATTERN_ORDER);
@preg_match('/^[x81-xFE]$/',$regs1[1][count($regs1[1])-1])?$intLen--:0;
@preg_match('/^(.{'.$intStart.'})(.{0,'.$intLen.'})/si', $strSource, $regs);
$strResult = $regs[2];
}else{
$strResult = "";
}
return $strResult;
}
function preg_substr2($strSource, $intStart=0, $intLen=32)
{
is_int($intLen) ?0:die("len isn't an integer");
is_int($intStart) ?0:die("start isn't a integer");
if ($intStart>=0 && $intLen>=0)
{
$strResult = substr($strSource, 0, $intStart);
@preg_match_all('/([x81-xFE].|.)/sim', $strResult, $regs, PREG_PATTERN_ORDER);
if(@preg_match('/^[x81-xFE]$/',$regs[1][count($regs[1])-1], $regs)){
$intStart--;
}
$strResult = substr($strSource, $intStart, $intLen);
@preg_match_all('/([x81-xFE].|.)/sim', $strResult, $regs, PREG_PATTERN_ORDER);
if(@preg_match('/^[x81-xFE]$/',$regs[1][count($regs[1])-1], $regs)){
$strResult = substr($strSource, $intStart, --$intLen);
}
}
return $strResult;
}
$strHTML = <<
ab

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

As a well-known short video platform in China, Kuaishou provides many creators with opportunities to showcase their talents and share their lives. When uploading a video, some novice creators may be confused about how to change the video posting location. This article will introduce you to how to change the publishing location of Kuaishou videos, and share some tips for Kuaishou video publishing to help you make better use of this platform to showcase your work. 1. Where is Kuaishou published and how to change its location? 1. Publishing interface: In Kuaishou APP, click the "Publish" button to enter the video publishing interface. 2. Location information: In the publishing interface, there is a "Location" column. Click to enter the location selection interface. 3. Change location: In the location selection interface, click the "Location" button to view the current location. If you want to change the location, click "Location"

There are a total of 20 origami birds in Croaker Film and Television Park on Star Dome Railway. Many players don’t know where the origami birds are in Crocker Film and Television Park. The editor has summarized the locations of each origami bird to help everyone. Search for it, and take a look at this latest summary of the locations of the origami birds in Croaker Film and Television Park for specific content. Guide to the Honkai Star Dome Railway: Origami Bird in Crook Movie Park Location 1, Crook Movie Park 1st Floor 2, and Crook Movie Park 2nd Floor Star Dome Railway

1. We open Meituan on the mobile phone, and then click on the takeout option in the upper left corner of the homepage. 2. After entering the takeout platform page, you can see the section with daily coupons on the homepage, click on it directly. 3. After entering the Tiantian God Voucher, you will see a lot of activities, click Finish, and then we can get rewards after completing the tasks.

Detailed explanation of the method of converting int type to string in PHP In PHP development, we often encounter the need to convert int type to string type. This conversion can be achieved in a variety of ways. This article will introduce several common methods in detail, with specific code examples to help readers better understand. 1. Use PHP’s built-in function strval(). PHP provides a built-in function strval() that can convert variables of different types into string types. When we need to convert int type to string type,

Golang regular expressions use the pipe character | to match multiple words or strings, separating each option as a logical OR expression. For example: matches "fox" or "dog": fox|dog matches "quick", "brown" or "lazy": (quick|brown|lazy) matches "Go", "Python" or "Java": Go|Python |Java matches words or 4-digit zip codes: ([a-zA

How to check if a string starts with a specific character in Golang? When programming in Golang, you often encounter situations where you need to check whether a string begins with a specific character. To meet this requirement, we can use the functions provided by the strings package in Golang to achieve this. Next, we will introduce in detail how to use Golang to check whether a string starts with a specific character, with specific code examples. In Golang, we can use HasPrefix from the strings package

Title: How to determine whether a string ends with a specific character in Golang. In the Go language, sometimes we need to determine whether a string ends with a specific character. This is very common when processing strings. This article will introduce how to use the Go language to implement this function, and provide code examples for your reference. First, let's take a look at how to determine whether a string ends with a specified character in Golang. The characters in a string in Golang can be obtained through indexing, and the length of the string can be

1. First open pycharm and enter the pycharm homepage. 2. Then create a new python script, right-click - click new - click pythonfile. 3. Enter a string, code: s="-". 4. Then you need to repeat the symbols in the string 20 times, code: s1=s*20. 5. Enter the print output code, code: print(s1). 6. Finally run the script and you will see our return value at the bottom: - repeated 20 times.
