Consider the following:
echo substr("abcdefgh", 1, -1);
// outputs bcdefg
echo substr("abcdefgh", 2, -2);
// outputs cdef
Seems like substr
is taking first numeric parameter as offset from start of the string and the second parameter as another offset from the end of the string.
I went through the official docs https://www.php.net/manual/en/function.substr.php They don't mention that there can be two offsets. They rather expect the second numeric parameter to be the length
.
So, does substr
take the second numeric argument as a second offset from the end when it is negative?
source https://stackoverflow.com/questions/70368353/how-does-php-substr-deal-with-two-offset-values
Comments
Post a Comment