problem with strings
Moderator: General Moderators
problem with strings
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 ?
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
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};
Last edited by dhrosti on Fri Jul 18, 2008 6:35 am, edited 1 time in total.
Re: problem with strings
your choice is good but i cant fix it
Re: problem with strings
sorry, i missed off one of the dollar signs, should work now.
Re: problem with strings
you mean something like taht ?
i not return something
Code: Select all
$lang_man = "this is a man";
$man = "man"; //
echo $lang_{$man};
i not return something
Re: problem with strings
i think something
return man ... but i dont want set the line " $$man = "man"; // "
any idea ?
Code: Select all
$lang_man = "this is a man";
$$man = "man"; //
echo "$lang_${$man}";
any idea ?
Re: problem with strings
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.';');
Last edited by dhrosti on Fri Jul 18, 2008 7:58 am, edited 1 time in total.
Re: problem with strings
ow this work well
on note
i find the easyest way to do this
and try
this
and work perfect
but when try to insert in my page like this
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
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"
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
any idea ?