Reply to Re: Partial macro expansion of variable and function name.

Your name:

Reply:


Posted by tihu on 05/05/06 20:53

ImOk wrote:
> I come from the Visual Foxpro world, which is one reason I love PHP.
> VFP is a scripting type language with macro substitution abilities
> similar to PHP.
>
> Besides the regular expansion I can do crazy things (VFP uses & instead
> of $):
>
> x="sales"
> sales="1000"
> salestax="8.25"
> ? &x
> .........prints 1000
> ? &x.tax
> ...........prints 8.25
>
> tr="trim"
> ? &tr.("xxx ")
> .........prints xxx
>
> ? 'This function is &tr.("xxxxx ")'
> ...... prints This function is trim("xxxxx ")
>
> In VFP the & indicates macro expansions and a space or a . idnicates
> the variable termination. Can I do this kind of partial expansion in
> PHP? There must be a trick somewhere.
>
> Thanks.

Variable variables might be what you are looking for, they use $$
instead of $

http://www.php.net/manual/en/language.variables.variable.php

Basically

$name = 'joe';
$getvar = 'name'
echo $$getvar; //prints $name so the output is 'joe'

It works with functions and class methods too

$tr = 'trim'
echo $tr(' xxxxx '); // calls the function trim() and prints
xxxx

Seeya

Tim

[Back to original 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

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