Page 1 of 1

problem with strings

Posted: Fri Jul 18, 2008 5:13 am
by jim_php
hello i developed one site with multilanguage support

so i have one lang file
and i have one example word like
$lang_click_here = "Please click here";

in my php script i use $lang_click_here and shown the word "Please click here"
but i want something different
i have one record in mysql and i load

example

$res->message // shown the word "click_here"

the best way i know to show rigth is

if($res->message = "click_here")
{
echo "$lang_click_here"; /// show Please click here
}


but i want something direct like
echo "".$lang_."$res->message"; //direct show please click here

but return "$lang_click_here" exactly not "please click here"



any idea to add the $lang_ in to mysql result as string and tranlsate from file ?

Re: problem with strings

Posted: Fri Jul 18, 2008 5:23 am
by dhrosti
from what i understand, you need to use "variable variables". so the value of one variable is used as the name of another variable, like...

Code: Select all

echo $lang_{$res->message};

Re: problem with strings

Posted: Fri Jul 18, 2008 6:05 am
by jim_php
your choice is good but i cant fix it

Re: problem with strings

Posted: Fri Jul 18, 2008 6:36 am
by dhrosti
sorry, i missed off one of the dollar signs, should work now.

Re: problem with strings

Posted: Fri Jul 18, 2008 6:41 am
by jim_php
you mean something like taht ?

Code: Select all

 
$lang_man = "this is a man";
 
$man = "man"; // 
 
echo $lang_{$man};
 
 

i not return something :(

Re: problem with strings

Posted: Fri Jul 18, 2008 6:46 am
by jim_php
i think something

Code: Select all

 
$lang_man = "this is a man";
 
$$man = "man"; // 
 
echo "$lang_${$man}";
 
 
return man ... but i dont want set the line " $$man = "man"; // "

any idea ?

Re: problem with strings

Posted: Fri Jul 18, 2008 6:51 am
by dhrosti
this is a bad way to do it, but it's the only way i can get it to work...

Code: Select all

$lang_man = "this is a man";
  
$man = "man"; //
  
eval('echo $lang_'.$man.';');

Re: problem with strings

Posted: Fri Jul 18, 2008 7:01 am
by jim_php
ow this work well

on note
i find the easyest way to do this

and try
this

Code: Select all

 
$lang_man = "this is a man";
 
$man = "man"; // 
 
echo "$lang_${$$man}";
 


and work perfect

but when try to insert in my page like this

Code: Select all

 
$lang_man = "this is a man";
 
echo "$lang_${$$res->gender}";    /// $res->gender return value "man"
 
 
i return this error
Catchable fatal error: Object of class stdClass could not be converted to string in /home/website/public_html/profile.php on line 99

Re: problem with strings

Posted: Fri Jul 18, 2008 8:06 am
by jim_php
any idea ?