PHP - Return everything after delimiter

后端 未结 7 1633
北恋
北恋 2021-01-19 01:00

There are similar questions in SO, but I couldn\'t find any exactly like this. I need to remove everything up to (and including) a particular delimiter. For example, given t

7条回答
  •  南笙
    南笙 (楼主)
    2021-01-19 01:21

    Shorter codes:

    To return everything BEFORE the FIRST occurence of a character, use strtok. Example:

    • strtok(16#/en/go, '#') will return 16

    To return everything AFTER the FIRST occurence of a character, use strstr. Example:

    • strstr(16#/en/go, '#') will return #/en/go (Includes search character '#')
    • substr(strstr(16#/en/go, '#'), 1) will return /en/go

    To return everything AFTER the LAST occurrence of a character, use strrchr. Example:

    • strrchr(16#/en/go, '/') will return /go (Includes search character '/')
    • substr(strrchr(16#/en/go/, '/'), 1) will return go

提交回复
热议问题