Explode only by last delimiter

后端 未结 11 1672
隐瞒了意图╮
隐瞒了意图╮ 2021-01-03 17:30

is there a way to use explode function to explode only by last delimiter occurrence?

$string = "one_two_  ... _three_four";

$explodeResultArray = e         


        
11条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-03 18:03

    For such a taks, you can just use strstr and strrchr:

    $valueBeforeLastUnderscore = rtrim(strrev(strstr(strrev($value), '_')), '_');
    $valueAfterLastUnderscore = ltrim(strrchr($value, '_'), '_');
    

    That being said, I like the regular expression answer more.

提交回复
热议问题