PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Tue May 18, 2004 2:58 pm
Kinda stupid maby but , i cant find my error
Code: Select all
function lang_set($option) {
if ($_GET['lang'] == 'en') {
include("inc/lang_en.inc");
}
if ($_GET['lang'] == 'es') {
include("inc/lang_es.inc");
}
}
// and some more..
$lang_set = lang_set($option);
//this wont include a language file.
echo $_GET['lang']; // returns the language (en / es / fr / .. )
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Tue May 18, 2004 3:11 pm
try just lang_set($option); rather then setting it to a $var that might solve your problem...
litebearer
Forum Contributor
Posts: 194 Joined: Sat Mar 27, 2004 5:54 am
Post
by litebearer » Tue May 18, 2004 3:15 pm
Code: Select all
function lang_set($option) {
if ($option == 'en') { include("inc/lang_en.inc"); }
if ($option == 'es') { include("inc/lang_es.inc"); }
return "yes"
}
lang_set($_GETї'lang']);
I think that should do the trick
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Tue May 18, 2004 3:33 pm
I am afraid that did not work. Thanks for trying
Outside the function it works fine..
However for later abuse, i would like to have been able to run inside a function();
PrObLeM
Forum Contributor
Posts: 418 Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:
Post
by PrObLeM » Tue May 18, 2004 3:49 pm
i dont see where you set $option...
dull1554
Forum Regular
Posts: 680 Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W
Post
by dull1554 » Tue May 18, 2004 4:15 pm
it really dont matter, he does not use $option in the lfunction
would you have to set $_GET as a global?
i.e.
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Tue May 18, 2004 4:33 pm
let me try that .. $_GET global thing there.. i might indeed forgotten that
Hmm, couldnt get this to work.
tried differant things.
Code: Select all
$lang = $_GET['lang'];
function lang_set($option);
global $lang;
if ($lang == 'en') {
include (this)
}
}
and all other options posted above.. including the one that does make use of the $option
Last edited by
ol4pr0 on Tue May 18, 2004 4:43 pm, edited 1 time in total.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Tue May 18, 2004 4:35 pm
$_GET is a 'superglobal', meaning it's always in scope. So no need for global $_GET
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Tue May 18, 2004 4:47 pm
That means something else must go wrong when putting that in a function .
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Tue May 18, 2004 4:51 pm
The function itself works when changing the include to a echo line
Code: Select all
if ($_GET['lang'] == 'en) {
echo "English included";
}
So is there something that wont allow me to include within a function ?
ol4pr0
Forum Regular
Posts: 926 Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador
Post
by ol4pr0 » Tue May 18, 2004 5:00 pm
As it seems i had to include the file that holds the language $vars aswell within the function not really the ideal solution tho.. since i can now only execute the function there where i need it..
This has mainly to do with a dhtml menu bar that i am using. so when exucuting that language settings the menu bar will apear on that spot aswell.
instead on the spot / place where it should be.
it works.. but there should be something else
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Tue May 18, 2004 5:44 pm
why not..
Code: Select all
$lang = (isset($_GET['lang'])?$_GET['lang']:"en");
if(is_readable($file = "lang/lang_$lang.inc"))
include($file);
else
die("unknown language");
unset($lang);