Jump to content

[SOLVED] How to force a string variable parsing?


duskshine

Recommended Posts

We know that the following code outputs "1",

	$i=1;
	$str= "$i";
	echo $str;

 

and this code outputs "$i"

	$i=1;
	$str = "$";
	$str .= "i";
	echo $str;

 

now my question is, suppose I have created a string using the second method, how may I force a string variable parsing to get it writes 1 instead of $i?

 

thanks,

 

 

@Wuhtzu: i failed to find a solution using variable variable :(

 

@MadTechie: i know that eval's dangerous but it seems i have to take what i have.

 

the fact is..well, im taking codes from a freak who did not use template to support multi-language, instead he uses things like

echo  $TEXT["general-info"];

----------------------

en.php:
$TEXT["general-info"] = "Hello world.";

----------------------

fr.php:
$TEXT["general-info"] = "Bonjour le monde.";

 

that works at first...until he left and the boss decided to put $TEXT["general-info"] into a db. now i get the whole damned "template" from database and of course, it writes $TEXT["general-info"] instead of either Hello World or Bonjour.

 

pretty dumb story i know..anyway, thank you guys very much :)

I find that using en.php & fr.php works quite well for out-sourcing :P

if you want to move it to a database then

create a table like this with 3 fields, Key (general-info), Lang (en), Wording("Hello world")

you could create a simple class to rebuild the array using the correct language

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.