PHP substr () function parameter explanation and usage explanation, phpsubstr
substr(string,start,length)
Parameters:
1. string is the string you want to intercept
2. start refers to the start position to be intercepted (0 indicates starting from the first character in the past and following, and negative indicates starting from the last digit)
Eg: start = 1, which indicates to intercept the second number starting from the past and following, start =-1, which indicates the first number starting from the back (the first one is not the second one) number start to intercept,
3. When length is positive, it is the length to be truncated. When it is negative, it is understood as removing the last few characters.
Eg: length = 3, which indicates to intercept three characters; length =-2, that is, remove the two characters at the end
Example ):
1, echo substr ("Hello world",-10,-2 );
Output: ello wor
Explanation:-10: What does it mean? You should be clear! Haha, of course, it indicates starting from the tenth character in the back and forth. Let's count the number carefully. d l r o w _ (do not forget the space) o l e, stop it, and start with e. Don't try H in front of it.
-2: What does it mean? You said I knew it, indicating that it would be better to ignore two characters! Awesome! That's it! So ld has nothing to do with you!
Are you clear about it?
2. If that one cannot understand (⊙ o ⊙ )?) Let's take a look at an example of getting started.
echo substr("Hello world",6,6);
Output: world
Explanation: "6" indicates that it starts with 7th characters (7x7). Of course, it is w;
6: Of course, it indicates intercepting six lengths (what, you say that world only has five lengths, really witty, and you have discovered this, of course, it will return if there is no interception at the end)
The following describes the usage of the php substr function.
I can't remember it, but I wrote:
<? Php echo substr ("Hello world! ", 6); Output world! When there are only two parameters, the first parameter table is a string, and the second parameter indicates that, starting from 6th, all the following parameters are truncated, starting from 0, and spaces are considered as one?>
<? Phpecho substr ("Hello world! ", 6, 4); when the output worl has three parameters, the second parameter is the starting position, and the third parameter is the length of the total truncation?>
Summary
The above is the explanation and usage of the PHP substr () function parameter introduced by the editor. I hope it will be helpful to you. If you have any questions, please leave a message for me, the editor will reply to you in a timely manner. Thank you very much for your support for the help House website!