duskshine Posted July 15, 2008 Share Posted July 15, 2008 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, Quote Link to comment https://forums.phpfreaks.com/topic/114834-solved-how-to-force-a-string-variable-parsing/ Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 you mean like this ? $i=1; $str = "$"; $str .= "i"; eval("echo $str;"); EDIT: something i don't recommend! Quote Link to comment https://forums.phpfreaks.com/topic/114834-solved-how-to-force-a-string-variable-parsing/#findComment-590489 Share on other sites More sharing options...
Wuhtzu Posted July 15, 2008 Share Posted July 15, 2008 You may also want to look at variable variables: http://www.devshed.com/c/a/PHP/Using-Variable-Variables-in-PHP/ http://www.phpbuilder.com/manual/en/language.variables.variable.php Quote Link to comment https://forums.phpfreaks.com/topic/114834-solved-how-to-force-a-string-variable-parsing/#findComment-590491 Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 i thought of variable variables, but thats in only really useful with the variable name not the value.. i think a bigger question is why do you want to do this ? Quote Link to comment https://forums.phpfreaks.com/topic/114834-solved-how-to-force-a-string-variable-parsing/#findComment-590494 Share on other sites More sharing options...
duskshine Posted July 15, 2008 Author Share Posted July 15, 2008 @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 Quote Link to comment https://forums.phpfreaks.com/topic/114834-solved-how-to-force-a-string-variable-parsing/#findComment-590513 Share on other sites More sharing options...
MadTechie Posted July 15, 2008 Share Posted July 15, 2008 I find that using en.php & fr.php works quite well for out-sourcing 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 Quote Link to comment https://forums.phpfreaks.com/topic/114834-solved-how-to-force-a-string-variable-parsing/#findComment-590534 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.