Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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