You are here: Re: Variable Variables in Classes « PHP Programming Language « IT news, forums, messages
Re: Variable Variables in Classes

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация