Here's an approach to create a multidimensional array according to a string's delimiters, i.e. we want to analyze...
"some text (aaa(b(c1)(c2)d)e)(test) more text"
... as multidimensional layers.
<?php
$string = "some text (aaa(b(c1)(c2)d)e)(test) more text";
/*
* Analyses the string multidimensionally by its opening and closing delimiters
*/
function recursiveSplit($string, $layer) {
preg_match_all("/\((([^()]*|(?R))*)\)/",$string,$matches);
// iterate thru matches and continue recursive split
if (count($matches) > 1) {
for ($i = 0; $i < count($matches[1]); $i++) {
if (is_string($matches[1][$i])) {
if (strlen($matches[1][$i]) > 0) {
echo "<pre>Layer ".$layer.": ".$matches[1][$i]."</pre><br />";
recursiveSplit($matches[1][$i], $layer + 1);
}
}
}
}
}
recursiveSplit($string, 0);
/*
Output:
Layer 0: aaa(b(c1)(c2)d)e
Layer 1: b(c1)(c2)d
Layer 2: c1
Layer 2: c2
Layer 0: test
*/
?>
----
Server IP: 69.147.83.197
Probable Submitter: 80.219.172.48
----
Manual Page -- http://www.php.net/manual/en/regexp.reference.recursive.php
Edit -- https://master.php.net/note/edit/102748
Del: integrated -- https://master.php.net/note/delete/102748/integrated
Del: useless -- https://master.php.net/note/delete/102748/useless
Del: bad code -- https://master.php.net/note/delete/102748/bad+code
Del: spam -- https://master.php.net/note/delete/102748/spam
Del: non-english -- https://master.php.net/note/delete/102748/non-english
Del: in docs -- https://master.php.net/note/delete/102748/in+docs
Del: other reasons-- https://master.php.net/note/delete/102748
Reject -- https://master.php.net/note/reject/102748
Search -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.