Exploding by Array of Delimiters

前端 未结 5 1923
伪装坚强ぢ
伪装坚强ぢ 2020-12-05 07:56

Is there any way to explode() using an array of delimiters?

PHP Manual:

array explode ( string $delimiter , string $string [, int $limit ] )

<
5条回答
  •  余生分开走
    2020-12-05 08:22

    function explode_by_array($delim, $input) {
      $unidelim = $delim[0];
      $step_01 = str_replace($delim, $unidelim, $input); //Extra step to create a uniform value
      return explode($unidelim, $step_01);
    }
    

    That's improved @65Fbef05's code. We use first delimiter, because "+delim+" may be used in original string.

提交回复
热议问题