seol Posted July 10, 2011 Share Posted July 10, 2011 Hello, I searched on the web and this forum, cant get what im looking for, maybe someone can help me with this. Im working on some classes for a CMS (own project) I wanted to make everything language independent, so i can change the language without having to edit all the website. This was the solution i choose: Constants. I use a PHP file for every language with a list of constants, so the key words that would be static, change depending which language file is loaded. My problem: when i get data from a SQL, lets say it gets a list, and save it to a variable, it doesnt change: Example define(L_IMG,"image"); $register= "L_IMG" (get it from SQL query) echo $register; L_IMG should appear as "image", but it appears as "L_IMG"... so, is there a way to force the variable to get the constant value? another way to do it? Quote Link to comment https://forums.phpfreaks.com/topic/241550-constat-for-multilanguage-site-problem/ Share on other sites More sharing options...
wildteen88 Posted July 10, 2011 Share Posted July 10, 2011 Dont place constants within quotes. Constants are not parsed within strings. Display a constants value echo CONSTANT_NAME_HERE; Using a constant within a string, you'd use concatenation echo "some text here " . CONSTANT_NAME_HERE . " more text here"; Quote Link to comment https://forums.phpfreaks.com/topic/241550-constat-for-multilanguage-site-problem/#findComment-1240788 Share on other sites More sharing options...
seol Posted July 10, 2011 Author Share Posted July 10, 2011 Ok, thanks for your answer, but my problem really is that the constant i want to change is loaded from a register of MySQL, the "L_IMG" its actually the answer from the query, its not written in the code. That is what i want to replace to the constant value, I have used constants as you indicated, no problem with that, the problem is when the constant is loaded from the query and then is echoed. Another problem is that the php can get from mysql either constants to be replace or real info. Maybe there is a better way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/241550-constat-for-multilanguage-site-problem/#findComment-1240872 Share on other sites More sharing options...
wildteen88 Posted July 10, 2011 Share Posted July 10, 2011 If just "L_IMG" is being returned from your query then you can use constant, eg echo constant($row['field_name_that_has_the_constant']); Quote Link to comment https://forums.phpfreaks.com/topic/241550-constat-for-multilanguage-site-problem/#findComment-1240874 Share on other sites More sharing options...
phpmady Posted July 10, 2011 Share Posted July 10, 2011 Hi, Just make it simple: There are two ways to achieve: Number One: Using CONSTANT arabic.php define("WEB_TITLE", "Welcome To My Site - Arabic Site"); english.php define("WEB_TITLE", "Welcome To My Site - ENGLISH Site"); Based On the Language load the above file and Print <?php echo WEB_TITLE; ?> Number Two: Using SQL TABLE phrases: Phrase_ID Language Phrase_Name Phrase_value 1 arabic WEB_TITLE WELOCME TO ARABIC 2 english WEB_TITLE WELOCME TO ENGLISH $phrases =""; $sql = "select * FROM phrases where Language = '".Language."'"; if($temps = $DB_site->query($sql)) { while ($temp = $DB_site->fetch_array($temps)) { $phrases[$temp['Phrase_Name']] = $temp['Phrase_value']; } } Print the VAlues: echo $phrases[WEB_TITLE]; echo $phrases[WEB_ADDRESS]; Thank you, all the best Quote Link to comment https://forums.phpfreaks.com/topic/241550-constat-for-multilanguage-site-problem/#findComment-1240884 Share on other sites More sharing options...
seol Posted July 10, 2011 Author Share Posted July 10, 2011 Thanks both for your answers, partly solve some doubts, but the problem I have was a little more specific. I finally got the solution: I needed to read form SQL a string that may o may not be a constant (for language portability purposes) so what i did was: $salida=defined($registro)?constant($registro):$registro; It may read a little slow... but nowadays it wont be too much of a problem. If you see some better way to do it? im open to other options. Quote Link to comment https://forums.phpfreaks.com/topic/241550-constat-for-multilanguage-site-problem/#findComment-1240990 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.