Last active
December 18, 2015 05:59
-
-
Save maor/5736517 to your computer and use it in GitHub Desktop.
[hello][/hello]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function count_nested_shortcodes( $shortcode ) { | |
// each shortcode uses the "[" chatacter twice. The first is of the opening tag, the last is for the closing tag. | |
// The main shortcode also has 2 occurances. Since we're looking for the nested shortcodes, we'll ignore the main one by subtracting 2 from the total outcome | |
return (int) ( substr_count( $shortcode, '[' ) / 2 ) - 2; | |
} |
why are we ignoring the first one? we are looking for the max depth of the array so can we add the The RecursiveIteratorIterator class for example and just spit out the array's depth ?
Maor take a look let me know what did I do wrong :(
$max_depth) { $max_depth = $depth; } } } return $max_depth; } ``` ?>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
looks good, can you add comments please ?