Re: Question on variable variables

From: Date: Sat, 17 Nov 2001 03:38:29 +0000
Subject: Re: Question on variable variables
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-74961@lists.php.net to get a copy of this message
Yes trying to get this to work: $curline = preg_replace("/<yabb\s+(\w+)>/","$$1",$curline); So for the current line I am looking for something like <yabb copyright> I want to replace that with the contents of $copyright. Can variable variables be used in regular expressions? Jeff ----- Original Message ----- From: "Christopher William Wesley" <cwwesley@udlug.org> To: <php-general@lists.php.net> Cc: "Jeff Lewis" <jeff@hyrum.net> Sent: Friday, November 16, 2001 10:38 PM Subject: Re: [PHP] Question on variable variables > On Fri, 16 Nov 2001, Jeff Lewis wrote: > > > What I need to do, however, is append a variable portion to a constant prefix. So I have a set of variables that are named $MYdog, $MYcat etc. and I need to do > > > > $a = "dog" > > ${"MY$a"} being the same as $MYdog > > > > Can this be done, and if so - how? I can't get it to work. > > So what you want is a base name with a vaiably-changing portion > concatenated? Gotcha! > > // you variable base name > $myVarBase = "MY"; > > $a = cat; > $something1 = "This Var Likes Cats"; > > $b = dog; > $something2 = "This Var Likes Dogs"; > > $myVarName1 = $myVarBase . $a; > $myVarName2 = $myVarBase . $b; > > // The same as $Mycat = "This Var Likes Cats"; > ${$myVarName1} = $something1; > > // The same as $Mydog = "This Var Likes Dogs"; > ${$myVarName2} = $something2; > > > g.luck > ~Chris /"\ > \ / September 11, 2001 > X We Are All New Yorkers > / \ rm -rf /bin/laden > > >

« previous php.general (#74961) next »