|
Posted by Giannis Vrentzos on 07/29/05 17:53
bettina@coaster.ch wrote:
> How should I define the global variable inside this function? What must
> be global is the lang.{$lang}.inc.php so that it can be read inside the
> function, isn't it?. I tried including the lang file in the function
> but I receive an error.
>
> require("lang.{$lang}.inc.php");
> function technique($t) {
> switch ($t) {
> case 'C':
> echo $charcoal;
> break;
> case 'O':
> echo $oil;
> break;
> case 'A':
> echo $acrylic;
> break;
> }
> }
>
> <? technique($myTechnik ?>
>
function technique($t) {
global $lang; // here we are using the global var $lang
$incFile = "lang.{$lang}.inc.php";
if ( file_exists($incFile) )
include ($incFile);
else
return;
switch ($t) {
case 'C':
echo $charcoal;
break;
case 'O':
echo $oil;
break;
case 'A':
echo $acrylic;
break;
}
}
Gvre
ps. To OP. You can put all strings in file "lang.{$lang}.inc.php" in an
array and access it like this. If you do it like this you don't have to
change the function technique($t) every time you put a new var in lang file.
// vars file
$strings = array (
"C" => "charcoal",
"O" => "oil",
"A" => "acrylic"
);
// index ? file
$incFile = "lang.{$lang}.inc.php";
if ( file_exists($incFile) )
include ($incFile);
else
return; // or any other action
// functions file
function technique($t) {
global $strings;
if (array_key_exists($t, $strings))
echo $strings[$t];
}
Navigation:
[Reply to this message]
|