I need to match a foreach string that looks like this
Code: Select all
{foreach="$errors" value="$error"}
html here
{/foreach}Code: Select all
private function _replace_foreach($src)
{
foreach($this->_vars_arrays AS $k => $v)
{
$k = '$' . "$k";
echo $k; //////this prints '$errors'... good .. if only I could get it in the regex
if(preg_match_all("#\{foreach=\"$k\" value=\".+?\"\}.+?{/foreach}#ism", $src, $matches))
{
echo '<pre>';
print_r($matches);
echo '</pre>';
} else
{
echo 'no matches!';
}
}
return $src;
}However when I replace $k (which should evalute to the text '$errors') with .+?, the match is found and comes out to {foreach="$errors" value="$error} html {/foreach} appears.. which is weird because $k = '$errors'.