Click to See Complete Forum and Search --> : call a define by using a vairable ?


k0r54
10-10-2005, 12:11 PM
Hi,

Ok senario: -

I have a notice page that i can link to and i also have a define like this : -

define('NOTICE_1', 'Msg 1')
define('NOTICE_2', 'Msg 2')

I refer to the notice page and put a $_get variable in to say the notice_id
How can i call the notice by using the $_get???

So in a sence i want to display

NOTICE_$_GET['notice_id']

so if the notice_id = 1 it will call the deifne NOTICE_1
but that obviously doesn't work!?

Thanks
k0r54

NogDog
10-10-2005, 03:07 PM
I believe you could use the constant() function for this. An untested example:

if(isset($_GET['notice_id']) and defined('NOTICE_'.$_GET['notice_id']))
{
$value = constant('NOTICE_'.$_GET['notice_id']);
}
else
{
# either set $value to default value or generate error, as appropriate
}

k0r54
10-11-2005, 10:47 AM
worked a treat :) thanks nogdog