How to Explode String Right to Left?

前端 未结 12 712
灰色年华
灰色年华 2020-12-31 03:22
$split_point = \' - \';
$string = \'this is my - string - and more\';

How can i make a split using the second instance of $split_point and not the

12条回答
  •  有刺的猬
    2020-12-31 03:59

    If I understand correctly, you want the example case to give you ('this is my - string', 'and more')?

    Built-in split/explode seems to be forwards-only - you'll probably have to implement it yourself with strrpos. (right-left search)

    $idx = strrpos($string, $split_point);
    $parts = array(substr($string, 0, $idx), substr($string, $idx+strlen($split_point)))
    

提交回复
热议问题