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() returns this array if matches are found:
Array
(
[0] => <nlist>#NEWSLIST#</nlist>
[1] => nlist
[2] => #NEWSLIST#
)
Array
(
[0] => <alist>#ACTIVITYLIST#</alist>
[1] => alist
[2] => #ACTIVITYLIST#
)
At the moment my preg_replace_callback function replaces the matches value with $matches[0]. What I am trying to do and wondering if even possible is to replace everything inside the tags ($matches[2]) and at the same time be able to do the $matches[1] check.
Test my regex here: http://rubular.com/r/k094nulVd5