Re: Question on variable variables

From: Date: Sat, 17 Nov 2001 23:34:35 +0000
Subject: Re: Question on variable variables
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-75018@lists.php.net to get a copy of this message
have you tried /e modifier? preg_replace("/<yabb\s+$tags[1]>/e",'${$1}', $curline); it's just a tip. ----- Original Message ----- From: "Jeff Lewis" <jeff@hyrum.net> To: <php-general@lists.php.net> Sent: Saturday, November 17, 2001 2:25 PM Subject: Re: [PHP] Question on variable variables > Thanks Jason and Christoper for replying, here is the solution I came up > with. It takes into account that there could be multiple instances of what > I'm looking for on the same line - got it working late last night: > > while (preg_match ("/<yabb\s+(\w+)>/",$curline,$tags)) > $curline = preg_replace("/<yabb\s+$tags[1]>/",${$tags[1]},$curline); > > Jeff > ----- Original Message ----- > From: "Jason G." <blair@nb.net> > To: "Jeff Lewis" <jeff@hyrum.net>; <php-general@lists.php.net> > Sent: Saturday, November 17, 2001 7:02 AM > Subject: Re: [PHP] Question on variable variables > > > > It seems to me that the use of a temp variable may be the clearest > > solution, and I doubt any overhead would matter really. > > > > $a = "dog"; > > $tmp = "MY".$a; //$tmp = "MYdog"; > > > > So the following two would be the same: > > $$tmp = "Spot"; > > $MYdog = "Spot"; > > > > Good Luck, > > > > Jason Garber > > IonZoft.com > > > > At 09:47 PM 11/16/2001 -0500, Jeff Lewis wrote: > > >I've a question regarding variable variable I was hoping someone could > > >help me with: > > > > > >All the examples in the manual have the entire variable name being > > >variable e.g. > > >$a = "hello" and > > >$$a being the same as $hello > > > > > >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. > > > > > >Jeff > > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#75018) next »