|
Posted by Dikkie Dik on 05/19/06 17:33
> For example:
>
> $this->animal = 'lamb';
> $this->string = 'Mary had a little {{animal}}';
>
> The goal is to extract 'animal' from the string (no problem), convert it
> to 'lamb' and replace it in the string (again, no problem). The question
> is, if I have 'animal', how do I get 'lamb'? In global space, I would
> simply have 'animal' in a variable, and use $$var to get 'lamb'.
>
Ah. Why not use str_replace?
And when you are using classes, you could as easily define a Variable
class with a Name and a Value method, and even a ToTemplate method that
puts the two pairs of curly braces around them.
If this is for a template engine, you probably have the name/value pairs
in a "named" array. In that case, a str_replace in a foreach loop does
the job just fine.
Best regards
Navigation:
[Reply to this message]
|