Summary of php substr function definition and usage (2022)
PHP中文网
Release: 2022-03-31 17:05:44
Original
8321 people have browsed it
php substr is a functional function developed based on the PHP language that can return a part of a string. Sometimes when we use php substr, some garbled characters will appear. How to solve it?
php substr basic syntax
string substr ( string $string , int $start [, int $length ] )
Copy after login
Returns a string of length starting from the start position in the string. The substr function intercepts characters by bytes. Chinese characters are 2 bytes in GB2312 encoding and 3 bytes in UTF-8 encoding. Therefore, if Chinese characters are truncated when intercepting a string of specified length, the returned result will be garbled.
php substr Parameters
Parameters
Description
##string
Required. Specifies a part of the string to be returned.
start
Required. Specifies where in the string to begin.
Positive numbers - start at the specified position in the string
Negative numbers - start at the specified position from the end of the string
0 - Starts at the first character in the string
length
Optional. Specifies the length of the returned string. The default is until the end of the string.
Positive number - the length returned from the position of the
start parameter
Negative number - the length returned from the end of the string length
Introduction: PHP substr_replace() function syntax and parameters. PHP substr_replace() function syntax substr_replace(string,replacement,start,length) Parameter Description string Required. Specifies the string to check. replacement required. Specifies what to insert
Introduction: php substr(),explode(),strrev(). substr(str,start,length); Example: substr(php tutorial is very good language,4,5); The output is is ve; When the length of startstr, the return is (); substr(php is very good language,26 ,5); s
Introduction: php substr_replace replaces characters at specified positions and memory corruption vulnerability. PHP tutorial substr_replace replaces characters at specified positions and memory corruption vulnerability Tips and comments Note: If start is a negative number and length is less than or equal to start, length is 0. $username =
##Introduction: PHP Substr library Function introduction. Beginner The following PHP Substr library function program is not perfect, but there is no problem in processing general Chinese (GB18030, GB2312, BIG5). This function is not suitable for UTF-8 encoded text. //$str characters
16. PHP substr interception of Chinese characters appears garbled problem solving_PHP tutorial
Introduction: PHP substr intercepts Chinese characters and solves the problem of garbled characters. We are using 1. Using the mb_substr interception of the mbstring extension library will avoid garbled characters. 2. Write the interception function yourself, but the efficiency is not as high as using the mbstring extension library. 3. If it is only
17. Explanation on the implementation skills of PHP substr function_PHP tutorial
Introduction: Explanation on the implementation skills of PHP substr function. I just sorted out the usage of the substr function and made a few examples to clear up the confusion for newcomers. Experts please pass by. Let’s first take a look at the syntax of the PHP substr function: string substr(string
##18.
Demonstrating the use of the PHP substr function_PHP tutorial
Introduction: Demonstrate the use of PHP substr function. PHP is the most commonly used language for dynamically developing WEB pages. String processing is the most commonly used in programming. Let’s talk about PHP substr in detail here. There are a bunch of applications similar to
##19.
php substr() function to implement filtering with a mantissa of 4_PHP tutorial
Introduction: The php substr() function implements filtering numbers with mantissas of 4. Today, a customer wants to generate 400 phone numbers in batches. The starting position is 10000. At first, I directly generated numbers such as 10004, but the merchants did not like this. Number, the filtered mantissa is
20.
php substr_replace replace string some examples_PHP tutorial
Introduction : Some examples of php substr_replace replacing strings. Substr_replace is a bit like str_replace, which directly replaces part of the string. Let me introduce to you how to use the substr_replace() function to replace part of the string.
21. php substr() function to intercept Chinese string garbled_PHP tutorial
Introduction: php substr() function to intercept The Chinese string is garbled. In PHP, if I want to use substr() to intercept the string in English, it will be a tragedy. But don’t worry, we can use other methods to solve it. p
22. PHP substr Interception of Chinese garbled problem solution_PHP tutorial
Introduction: Solution to the problem of intercepting Chinese garbled characters with PHP substr. PHP provides us with several character interception functions, including substr, mb_substr, and mb_strcut functions. Some of our PHP beginners will use substr to intercept Chinese characters, but they find that the Chinese characters will be garbled
Introduction: Several application examples of the PHP substr_replace() function. Introduction to substr_replace() function The substr_replace() function replaces part of a string with another string. Syntax: substr_replace(string,replacement,start,length) parameter string, must
Introduction: Several program applications of PHP substr() function. Introduction to substr() function The substr() function returns a part of a string. Syntax: substr(string,start,length). string: required. Specifies a part of the string to be returned. start: Must
##Introduction: php substr,iconv_substr,mb_substr . When PHP intercepts Chinese strings, it often uses two functions iconv_substr and mb_substr. How to choose between these two functions? You will understand by referring to the examples introduced in this article.
For more PHP related knowledge, please visit PHP Chinese website!
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