search

Home  >  Q&A  >  body text

PHP substr() function

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

ringa_leeringa_lee2786 days ago815

reply all(2)I'll reply

  • 迷茫

    迷茫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)

    reply
    0
  • 为情所困

    为情所困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之后的字符都被省略了,所以截取的字符串也是空,所以说length0Similarly 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

    reply
    0
  • Cancelreply