We all know that the string intercept characters in JS have functions substr and substring, and PHP, PHP, there is no directly available substring function, but there are substr functions.
Don't believe you can test it. Here's a good piece of code.
< $a = "Me"; Echo (substr ($a,,));//Output me?> The following is an error code <? $a = "Me"; Echo (subString ($a,,)); >
The substr () function returns a portion of a string.
SUBSTR (String,start,length)
String: Strings to intercept
Start
Positive number-starts at the specified position in the string
Negative number-starts at the specified position from the end of the string
0-Starts at the first character in a string
Length
Optional. Specifies the length of the string to return. The default is until the end of the string.
Positive number-returns from the position where the start parameter is located
Negative-returns from the end of the string
The usage of PHP substr () is detailed
Definition and usage
The substr () function returns a portion of a string. Using the substr () function to intercept Chinese can be garbled and it is recommended to use the MB_SUBSTR () function to intercept Chinese.
Grammar
SUBSTR (String,start,length)
Parameters |
Description |
String |
Necessary. A string that specifies the part to return. |
Start |
Necessary. Specifies where to start the string.
- Positive-starts
- negative-start
- 0-starts at the first character in the string
|
Length |
Optional. Specifies the length of the string to return. The default is until the end of the string.
- Positive number-returns from the position where the start parameter is located
- Negative-returns from the end of the string
|
Hints and Notes
Note: If start is negative and length is less than or equal to start, length is 0.
Example
<?php$str = ' Hello world! '; Echo substr ($STR, 4); o world! Start from the 4th to the right to the end of Echo substr ($str, 4, 5); O Wor 5-bit echo substr ($STR, 4,-1) to the right from the left 4th; O World left 4th and right from the 1th character Echo substr ($str,-8, 4); O wo right from the 8th start to intercept the right 4-bit echo substr ($STR, -8,-2); o Worl the 8th and right from the 2nd character?>