i want to return array from string like wordpress short code does , but i want the array to be like the example
i have this string
$str = 'codes example : [code lang="php"]<?php echo "Hello Wold" ; ?>[/code] [code lang="html"]<b>Hello</b>[/code]' ;
and i want to return contain
array(
array(
'code' => '[code lang="php"]<?php echo "Hello Wold" ; ?>[/code]' ,
'function' => 'code' ,
'attr' => array( 'lang' => 'php' ) ,
'value' => '<?php echo "Hello Wold" ; ?>'
) ,
array(
'code' => '[code lang="html"]<b>Hello</b>[/code]' ,
'function' => 'code' ,
'attr' => array( 'lang' => 'html' ) ,
'value' => '<b>Hello</b>'
)
)
i tried to do it using preg_match_all
i used this pattern /[[a-z]{3,}+ *[a-z]{2,}=(.*)+ *](.*)[\/[a-z]{3,}]/U
and the result was
Array ( [0] => Array ( [0] => [link href="http://www.php.net" text="php"][/link] [1] => [code lang="php"][/code] [2] => [code lang="html"]Hello[/code] ) [1] => Array ( [0] => " [1] => " [2] => " ) [2] => Array ( [0] => [1] => [2] => Hello ) )