note 99167 added to function.explode
| From: | m0gr14 at gmail dot com | Date: | Sat, 31 Jul 2010 14:02:51 +0000 |
| Subject: | note 99167 added to function.explode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-171284@lists.php.net to get a copy of this message | ||
Here's a function for "multi" exploding a string.
<?php
//the function
//Param 1 has to be an Array
//Param 2 has to be a String
function multiexplode ($delimiters,$string) {
$ary = explode($delimiters[0],$string);
array_shift($delimiters);
if($delimiters != NULL) {
foreach($ary as $key => $val) {
$ary[$key] = multiexplode($delimiters, $val);
}
}
return $ary;
}
// Example of use
$string = "1-2-3|4-5|6:7-8-9-0|1,2:3-4|5";
$delimiters = Array(",",":","|","-");
$res = multiexplode($delimiters,$string);
echo '<pre>';
print_r($res);
echo '</pre>';
//returns
/*
Array
(
[0] => Array
(
[0] => Array
(
[0] => Array
(
[0] => 1
[1] => 2
[2] => 3
)
[1] => Array
(
[0] => 4
[1] => 5
)
[2] => Array
(
[0] => 6
)
)
[1] => Array
(
[0] => Array
(
[0] => 7
[1] => 8
[2] => 9
[3] => 0
)
[1] => Array
(
[0] => 1
)
)
)
[1] => Array
(
[0] => Array
(
[0] => Array
(
[0] => 2
)
)
[1] => Array
(
[0] => Array
(
[0] => 3
[1] => 4
)
[1] => Array
(
[0] => 5
)
)
)
)
*/
?>
----
Server IP: 194.153.94.10
Probable Submitter: 85.2.140.100
----
Manual Page -- http://www.php.net/manual/en/function.explode.php
Edit -- https://master.php.net/note/edit/99167
Del: integrated -- https://master.php.net/note/delete/99167/integrated
Del: useless -- https://master.php.net/note/delete/99167/useless
Del: bad code -- https://master.php.net/note/delete/99167/bad+code
Del: spam -- https://master.php.net/note/delete/99167/spam
Del: non-english -- https://master.php.net/note/delete/99167/non-english
Del: in docs -- https://master.php.net/note/delete/99167/in+docs
Del: other reasons-- https://master.php.net/note/delete/99167
Reject -- https://master.php.net/note/reject/99167
Search -- https://master.php.net/manage/user-notes.php