我想像wordpress短代码那样从字符串返回数组,但我希望数组像示例
我有这个字符串
$str = 'codes example : [code lang="php"]<?php echo "Hello Wold" ; ?>[/code] [code lang="html"]<b>Hello</b>[/code]' ;
我想返回包含
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>'
)
)
我尝试使用preg_match_all
我用了这个模式/[[a-z]{3,}+ *[a-z]{2,}=(.*)+ *](.*)[\/[a-z]{3,}]/U
结果是
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 ) )