[PHP] Variable variable using constant

2011-10-12 Thread Marc Guay
Hi folks,

Let's say that I have 2 constants

DEFINE('DESKTOP_URL_en', http://www.website.com/index.php?page=home;); 
DEFINE('DESKTOP_URL_fr', http://www.website.com/index.php?page=accueil;);  


and I would like to populate the value of an href with them depending
on the user's language.  $_SESSION['lang'] is either 'en' or 'fr'.
How would I go about referring to this variable?

I have tried:

${'DESKTOP_URL_'.$_SESSION['lang']};
${DESKTOP_URL'.'_'.$_SESSION['lang']};
{DESKTOP_URL'.'_'.$_SESSION['lang']};
etc, to no avail.

If it is a regular variable I'm fine, it's the CONSTANT_FORMAT that
seems to be causing my brain some issues.

Thanks,
Marc

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variable variable using constant

2011-10-12 Thread Robert Williams
On 10/12/11 11:51, Marc Guay marc.g...@gmail.com wrote:


Let's say that I have 2 constants

DEFINE('DESKTOP_URL_en', http://www.website.com/index.php?page=home;);
DEFINE('DESKTOP_URL_fr',
http://www.website.com/index.php?page=accueil;);

and I would like to populate the value of an href with them depending
on the user's language.  $_SESSION['lang'] is either 'en' or 'fr'.
How would I go about referring to this variable?


Try:

   $var = constant('DESKTOP_URL_' . $_SESSION['lang']);


Regards,
Bob

--
Robert E. Williams, Jr.
Associate Vice President of Software Development
Newtek Businesss Services, Inc. -- The Small Business Authority
https://www.newtekreferrals.com/rewjr
http://www.thesba.com/







Notice: This communication, including attachments, may contain information that 
is confidential. It constitutes non-public information intended to be conveyed 
only to the designated recipient(s). If the reader or recipient of this 
communication is not the intended recipient, an employee or agent of the 
intended recipient who is responsible for delivering it to the intended 
recipient, or if you believe that you have received this communication in 
error, please notify the sender immediately by return e-mail and promptly 
delete this e-mail, including attachments without reading or saving them in any 
manner. The unauthorized use, dissemination, distribution, or reproduction of 
this e-mail, including attachments, is prohibited and may be unlawful. If you 
have received this email in error, please notify us immediately by e-mail or 
telephone and delete the e-mail and the attachments (if any).

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Variable variable using constant

2011-10-12 Thread Marc Guay
   $var = constant('DESKTOP_URL_' . $_SESSION['lang']);

Very nice, thank you.

Marc

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php