Re: cannot access inc files from a function
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: cannot access inc files from a function

From: <bettina@coaster.ch>
Date: Sat Jul 30 2005 - 11:59:15 CEST

Hallo Giannis, that of putting everything in my lang file so that I
don't have to change the function every time I add a new variable works
fine! Thank you for the tip!

Giannis Vrentzos schrieb:

> 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];
>
> }
Received on Tue Oct 18 02:06:20 2005