Parse shortcode to array
i need to parse WordPress shortcode to array, in php, for example:
[parrent_shortcode attribute='1' attribute2='a']
[shortcode atrribute1=true attribute2=true]This is first
content[/shortcode]
[shortcode atrribute1=false]This is second content[/shortcode]
[/parrent_shortcode]
to become:
Array(
[name] => 'parrent_shortcode'
[atts] => Array(
[attribute] => '1'
[attribute2] => 'a'
)
[content] => Array(
[child1] => Array(
[name] => 'shortcode'
[atts] => Array(
[atrribute1] => true
[attribute2] => true
)
[content] => 'This is first content'
)
[child2] => Array(
[name] => 'shortcode'
[atts] => Array(
[atrribute1] => false
)
[content] => 'This is second content'
)
)
)
Also shortcodes can be without parrent wrapper and can be single
(selfclosing) without content. Also attribute can have spaces in it.
I try to accomplish it using explode but ther are so many combinations..
No comments:
Post a Comment