I realise similar questions have come up a few times, but I can't seem to find one that will help with what I am trying to do.
We have a config.php file which is basically a list of variables that a user sets, along with their values, eg:
$OUR_EMAIL_ADDRESS = '[email protected]';
$OUR_WEBSITE = 'www.test.com';
Just like all the other users we want to transfer a PHP value via Javascript.
We have a way of doing this already, via ajax - but it is not as flexible as we would like as each variable needs a custom script / php page:
Part 1 - javascript (jquery)
$.get("/getConfig_email.php", function(email){
alert(email);
});
part 2: getConfig_email.php
<?php
echo $OUR_EMAIL_ADDRESS_VALUE;
?>
The question:
Is there a way that PHP can use a string as a variable name? ie. What I want to do is this:
Part 1 - javascript (jquery)
$.get("/getConfig.php?name=OUR_EMAIL_ADDRESS_VALUE", function(email){
alert(email);
});
part 2: getConfig.php
<?php
$var_name = $_GET['name'];
//some magic here to turn the name of the variable
//in to the actual variable - a bit like a reverse extract
echo $var_name.value;
?>
What do you think? Is this possible somehow - I'm hoping there is just a php command that can do this for me!
Many thanks in advance.