You are here: Re: cannot access inc files from a function « PHP Programming Language « IT news, forums, messages
Re: cannot access inc files from a function

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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация