Jump to content

converting a variable

  • Please log in to reply
2 replies to this topic

#1 Guest_devans_*

  • Guests

Posted 30 June 2006 - 11:21 PM

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:
// english.php
// included english file
// blah blah a bunch more...

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:

// include above english file

// 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_ID
echo $some_info;  // this shows _USER_ID, not User ID

Is there any way of making the $some_info var echo the defined definition (i.e., in this case, User ID)?


#2 nogray

  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 30 June 2006 - 11:38 PM

you can try the eval function

echo eval($some_info.";");


#3 devans

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 04 July 2006 - 04:29 PM

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...

define("TEST_VAL","test value");
$test = "TEST_VAL";
echo $test . "<br/>";	// echos TEST_VAL
eval("\$test = $test;");
echo $test . "<br/>";	// echos test value

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users