How to understand PHP substr() function usage: If the start parameter is a negative number and length is less than or equal to start, then length is 0.
This sentence
迷茫2017-05-24 11:32:51
Use the php function, write a demo to test it
substr('abcdefg', -4, -2) and substr('abcdefg', -4, -6)
为情所困2017-05-24 11:32:51
If a negative length is provided, length characters at the end of the string will be omitted (if start is a negative number, it will be counted from the end of the string). If start is not in this text, FALSE will be returned.
Reference: http://php.net/manual/zh/func...
Look at sbbstr('abcdefg', -4, -3)
, so the character with length 3
at the end of the character will be omitted. The actual intercepted string is abcd
;sbbstr('abcdefg', -4, -3)
,所以该字符末尾长度为3
的字符会被省略真正被截取的字符串为abcd
;
同理sbbstr('abcdefg', -4, -5)
,当length
小于等于start
时,包括下标为-4
之后的字符都被省略了,所以截取的字符串也是空,所以说length
为0
Similarly to sbbstr('abcdefg', -4, -5)
, when length
is less than or equal to start
, including characters after the subscript -4
are omitted, so the intercepted string is also empty, so length
is 0