note 96942 added to function.explode

From: Date: Wed, 24 Mar 2010 10:14:19 +0000
Subject: note 96942 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-167344@lists.php.net to get a copy of this message
<?php // {{{ public static function explodeRecursive($delims, $string, $delimdelim = NULL) // {{{ Doc /** * Recursively explode a string * * Explodes a string into a multi-demensional array at the delimeters * specified in $delims. The top level is created from the first delim * with subsequent levels at each further delim * * <code> * * $testString = "two bad sentences. In this paragraph</p> * <p>And three. bad sentences in. this paragraph"; * * // To split into paragraphs sentences and words we delimit at </p><p>, * // full stop (.) and space ( ) $delim = '</p><p>,., ' * // setting $delimdelim to comma (,) * $testArray = explodeRecursive('</p><p>,., ', $testString, ','); * * print_r ($testArray); * * // Will output * * Array * ( * [0] => Array * ( * [0] => Array * ( * [0] => two * [1] => bad * [2] => sentences * ) * * [1] => Array * ( * [0] => In * [1] => this * [2] => paragraph * ) * * ) * * [1] => Array * ( * [0] => Array * ( * [0] => And * [1] => three * ) * * [1] => Array * ( * [0] => bad * [1] => sentences * [2] => in * ) * * [2] => Array * ( * [0] => this * [1] => paragraph * ) * * ) * * ) * * </code> * * @param string $string The string to be exploded * * @param string $delims a list of delimiters Each delimiter is one * character unless you specify * a $delimdelim * * @param string $delimdelim Optional single character that specifies the * delimiter in the $delim string. * * @return array * * @author Will Bickerstaff **/ // }}} public static function explodeRecursive($delims, $string, $delimdelim = NULL){ $return = array(); if (strlen($delims) > 1){ if ($delimdelim === NULL){ $delims = str_split($delims); } else { $delims = explode($delimdelim, $delims); } $thisdelim = $delims[0]; array_shift($delims); } else { $thisdelim = $delims; } $return = explode($thisdelim, $string); if (is_array($delims)){ $delims = implode($delimdelim,$delims); foreach($return as $k => $v){ $v = trim($v); $return[$k] = explodeRecursive($delims, $v, $delimdelim); } } return $return; } // }}} ?> ---- Server IP: 87.124.86.45 Probable Submitter: 87.243.197.20 (proxied: 87.243.197.20) ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- https://master.php.net/note/edit/96942 Del: integrated -- https://master.php.net/note/delete/96942/integrated Del: useless -- https://master.php.net/note/delete/96942/useless Del: bad code -- https://master.php.net/note/delete/96942/bad+code Del: spam -- https://master.php.net/note/delete/96942/spam Del: non-english -- https://master.php.net/note/delete/96942/non-english Del: in docs -- https://master.php.net/note/delete/96942/in+docs Del: other reasons-- https://master.php.net/note/delete/96942 Reject -- https://master.php.net/note/reject/96942 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#167344) next »