Home>Article>Backend Development> How to intercept the last few characters of a specified string in php
In PHP, you can use the substr() function to intercept the last few characters of the specified string. You only need to set the second parameter "$start" of the function to a negative number to start from the end of the string. Starting at the "$start" character from the front, all characters are intercepted; the syntax is "substr($str,$start)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
When processing strings, sometimes we The string needs to be intercepted. In PHP, intercepting strings can be achieved through PHP's predefined function substr().
The substr() function can intercept a certain length of characters from a specified position in a string. The intercepted characters can be called "substring" or "substring". The syntax format is as follows:
substr($string, $start [, $length])
The parameter description is as follows:
Example: intercept the last few characters of the specified string
If you want to intercept the last few characters of the specified string, just need Set the second parameter "$start" of the substr() function to a negative number to intercept all characters starting from the "$start" character from the end of the string.
Output:
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to intercept the last few characters of a specified string in php. For more information, please follow other related articles on the PHP Chinese website!