function();

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

Post Reply
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

function();

Post by ol4pr0 »

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 / .. )
User avatar
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 »

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 »

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
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

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();
User avatar
PrObLeM
Forum Contributor
Posts: 418
Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:

Post by PrObLeM »

i dont see where you set $option...
User avatar
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 »

it really dont matter, he does not use $option in the lfunction

would you have to set $_GET as a global?

i.e.

Code: Select all

global $_GET;
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

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.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

$_GET is a 'superglobal', meaning it's always in scope. So no need for global $_GET
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

That means something else must go wrong when putting that in a function .
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

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 ?
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

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 ;-)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

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);
Post Reply