- <? PHP
- $str = "123456789";
- Echo substr ($str, 0, 3);//intercept 3-bit characters from the first character on the left: result: 123
- Echo substr ($str, 3, 3);//intercept 3-bit characters from the 3rd character on the left: result: 456
- ?>
[HTML]View PlainCopy
- <? PHP
- $Rest = substr ("abcdef",-1); Return "F"
- $Rest = substr ("abcdef",-2); Back to "EF"
- $Rest = substr ("ABCdef",-3, 1);//return "D"
- ?>
[HTML]View PlainCopy
- <? PHP
- $Rest = substr ("ABCdef", 0,-1); Back to "ABCDE"
- $Rest = substr ("ABCdef", 2,-1); Back to "CDE"
- $Rest = substr ("ABCdef", 4,-4); Return ""
- $Rest = substr ("ABCdef",-3,-1);//Return to "de"
- ?>
[HTML]View PlainCopy
- <? PHP
- echo substr (' abcdef ', 1); Bcdef
- echo substr (' abcdef ', 1, 3); Bcd
- echo substr (' abcdef ', 0, 4); Abcd
- echo substr (' abcdef ', 0, 8); ABCdef
- echo substr (' abcdef ',-1, 1); F
- To access a single character in a string
- You can also use the brackets
- $string = ' abcdef ';
- echo $string [0]; A
- Echo $string [3]; D
- echo $string [Strlen ($string)-1]; F
- ?>
PHP intercepts string functions;