I have a string containing multiple shortcodes like this:
// string contain multi shortcode
$string = '[code_1]
[code_2 attr_2="test2"]Here2[/code_2]
[code_3 attr_3="test3"]Here3[/code_3]
[code_4 attr_4="test4"]
[code_4_1 attr_41="test41"]Here41[/code_4_1]
[code_4_2 attr_42="test42"]Here42[/code_4_2]
[/code_4]';
And I have a list key array containing shortcode names:
// list key
$list_key = array(
'code_1',
'code_2',
'code_3',
'code_4',
'code_4_1',
'code_4_2',
);
How can I generate the following array?
array(
array(
"name" => "code_1",
),
array(
"name" => "code_2",
"attr" => array(
"attr_2" => "test2"
),
"content" => "Here2",
),
array(
"name" => "code_3",
"attr" => array(
"attr_3" => "test3"
),
"content" => "Here3",
),
array(
"name" => "code_4",
"attr" => array(
"attr_4" => "test4"
),
"content" => array(
array(
"name" => "code_4_1",
"attr" => array(
"attr_41" => "test41"
),
"content" => "Here41",
),
array(
"name" => "code_4_2",
"attr" => array(
"attr_42" => "test42"
),
"content" => "Here42",
)
),
)
);
I want to do this outside of Wordpress. How can I do that?