function replaceContent($matches = array()){
if ($matches[1] == "nlist"){
// do stuff
return "replace value";
} elseif ($matches[1] == "alist"){
// do stuff
return "replace value";
}
return false;
}
preg_replace_callback('/<([n|a]list)\b[^>]*>(.*?)<\/[n|a]list>/','replaceContent', $page_content);
$matches in replaceContent() は、一致が見つかった場合に次の配列を返します。
Array
(
[0] => <nlist>#NEWSLIST#</nlist>
[1] => nlist
[2] => #NEWSLIST#
)
Array
(
[0] => <alist>#ACTIVITYLIST#</alist>
[1] => alist
[2] => #ACTIVITYLIST#
)
現在、私の preg_replace_callback 関数は、一致する値を $matches[0] に置き換えています。私がやろうとしているのは、タグ ($matches[2]) 内のすべてを置き換えると同時に、$matches[1] チェックを実行できるかどうかということです。
ここで正規表現をテストします: http://rubular.com/r/k094nulVd5