How php reads the last few characters of a string
This article mainly explains "php how to read a few characters after the string", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let Xiaobian take you to learn "php how to read a few characters after the string"!
In php, you can use the substr() function to read the last few characters of a string by setting the second argument of the function to a negative value and omitting the third argument; the syntax is "substr(string,-n)", which means reading all characters from the end of the string to the nth character.
Operating environment of this tutorial: Windows 7 system, PHP7.1 version, DELL G3 computer
In php, you can use the substr() function to read the last few characters of a string.
The substr() function returns a portion of a string.
Simply omit the third argument to the function and set the second argument to a negative value (-n), n specifying the next few characters you want to read
Implementation example:
Description:
The substr() function intercepts a certain length of characters from a specified position in a string. This truncated character can be called a "substring" or a "substring". Its syntax is as follows:
substr($string, $start [, $length])
Parameters are described as follows:
$string: string to be truncated, the string contains at least one character;
$start: the starting position of the truncated string;
If $start is non-negative, then the string will be truncated starting at the $start character of $string, and $start will be evaluated starting at 0. For example, in the character string "abcdef," the character at position 0 is "a," the character string at position 2 is "c," and so on;
If $start is negative, then the string starts at the $start character counting forward from the end of $string, and $start starts at-1. For example, in the string "abcdef," the character at position-1 is "f," the character at position-3 is "d," and so on;
If the length of $string is less than $start, FALSE is returned.
$length: Optional parameter indicating the length of the truncated string.
If $length is positive, the string will be truncated up to $length characters backward from the $start position;
If $length is negative, then the $length characters at the end of $string will be omitted (starting from the end of the string if $start is negative);
If the value of $length is 0, FALSE, or NULL, an empty string is returned;
If $length is not provided, the returned substring starts at the $start position and continues to the end of the string.
At this point, I believe that we have a deeper understanding of "how php reads a few characters after a string," so let's actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!