- array_push: documentation ( source)
- print_r: documentation ( source)
- preg_match_all: documentation ( source)
<?php
preg_match_all(
'#\[(link)(.*?)!?\](.*?)\[\/\\1\]#i',
'[link href="http://www.google.com" title="Google" target="_blank"]Google[/link]
[link href="http://www.facebook.com"]Facebook[/link]
[link href=\'http://www.twitter.com\' rel="nofollow"]Twitter[/link]',
$StrMatches
);
/* $StrMatches[0] = Full tag string
* $StrMatches[1] = Tag name
* $StrMatches[2] = tag params string
* $StrMatches[3] = Tag content
* */
print_r($StrMatches);
$ParamList = array();
foreach ($StrMatches[2] as $TagParamStr )
{
preg_match_all('#\s*([^=]+)=[\'|"]([^\'|"]*)[\'|"]#', $TagParamStr, $ParamMatches);
array_push($ParamList, $ParamMatches);
}
/* $ParamList[0] = Full param string
* $ParamList[1] = Param name
* $ParamList[2] = Param value
* */
print_r($ParamList);