Jeff schrieb:
Quote:
I've been struggling with this for a while.
>
Here's what I'm trying to do:
>
private function makeMiniTemplate($ARRAY){
>
/*
>
$ARRAY looks like this:
$ARRAY['h']='Some Value';
$ARRAY['mce']='Something else';
>
*/
>
>
$template=<<<allthis
<div>[h]</div>
<div>[mce]</div>
...
>
allthis;
>
/*
I want to replace [h] with $ARRAY['h'];
Drives me crazy not to be able to use nowdocs in classes but that's
another story...
*/
>
>
$template=preg_replace_callback(
"/\[(.*?)\]/s",
create_function('$matches','echo $ARRAY[$matches[1]];'),
$template);
>
return $template;
}
>
>
So, I don't know how to pass in $ARRAY as $ARRAY is not "scoped" inside
the create_function. It always comes up empty.
>
I don't see how to do this using callbacks either. I'm a little short of
understanding on how this works. I've tried a number of different
approaches.
>
How do I do this?
>
Jeff
Maybe Iīm blind :-) Or I donīt understand your question....
But to replace ALL [h] with $a:
$t = str_replace("[h]", $a, $t);