Guest devans Posted June 30, 2006 Share Posted June 30, 2006 This is probably an easy one, but great if someone could suggest a solution =)I'm including various language files, depending on which is selected. For any language, I define them such:[code]<?php// english.php// included english fileDEFINE('_USER_ID','User ID');// blah blah a bunch more...?>[/code]All is wonderful, but then I got the great idea of making my db names match. The question is, how do I convert a string to a variable (if that makes any sense)? For example:[code]<?php// include above english fileinclude("english.php");// do a query$sql = 'SELECT foo FROM bar';$result = mysql_query($sql) or die (mysql_errno().": select ".mysql_error()."<BR>" . $sql);while ($row = mysql_fetch_array($result)) { $some_info = $row['foo'];}// $some_info = _USER_IDecho $some_info; // this shows _USER_ID, not User ID?>[/code]Is there any way of making the $some_info var echo the defined definition (i.e., in this case, User ID)?daniel Quote Link to comment https://forums.phpfreaks.com/topic/13344-converting-a-variable/ Share on other sites More sharing options...
nogray Posted June 30, 2006 Share Posted June 30, 2006 you can try the [url=http://us3.php.net/manual/en/function.eval.php]eval[/url] function[code]echo eval($some_info.";");[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13344-converting-a-variable/#findComment-51466 Share on other sites More sharing options...
devans Posted July 4, 2006 Share Posted July 4, 2006 Thanks nogray, you set me on the right track! For any others having the same issue, this was the final solution that worked for me...[code]<?phpdefine("TEST_VAL","test value");$test = "TEST_VAL";echo $test . "<br/>"; // echos TEST_VALeval("\$test = $test;");echo $test . "<br/>"; // echos test value?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13344-converting-a-variable/#findComment-52936 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.