note 122290 deleted from function.explode by salathe

From: Date: Mon, 21 Sep 2020 14:49:29 +0000
Subject: note 122290 deleted from function.explode by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215332@lists.php.net to get a copy of this message
Note Submitter: KEINOS ---- If you want to have delimiter option as an array WITH limit option. ( an extended approach from php-at-metehanarslan-dot-com's ) <?php /** * explode_multi function. * * Split a string by an array of string and limitable * * @access public * @param array $delimiters * @param string $string_raw * @param integer $limit (default: PHP_INT_MAX) * @return array */ function explode_multi($delimiters, $string_raw, $limit = PHP_INT_MAX) { $string_tmp = (string) $string_raw; $string_rep = str_replace($delimiters, $delimiters[0], $string_raw); $exploded = explode($delimiters[0], $string_rep, $limit); $result = array(); for ($key = 0; $key < ($limit-1); $key++) { $pattern = $exploded[$key]; $string_tmp = preg_replace("/${pattern}/", '', $string_tmp, 1); $result[] = $pattern; } $result[] = trim($string_tmp); return $result; } ?>

« previous php.notes (#215332) next »