PDA

View Full Version : define() with array() - PHP



Dynash
July 8th, 2008, 15:34
How do you do an array inside of an define?
Here's what I have:



<?php
// previous defines for database etc.
define('LANGUAGE', 'english');
?>

and this is what I think I do: (I want multiple languages!)


<?php
define('LANGUAGE', array(
'english',
'russian',
'french'));
?>


etc, is that what I do? If not, (I'm guessing not) how would I do it?

Dynash
July 8th, 2008, 15:52
Or, would I do this, it just made me think:



<?php
$language_array = array(
"1" => 'english',
"2" => 'russian',
"3" => 'spanish'
);
// this would be in the config file of course, where you would replace # with 1,2,3 etc.
define('LANGUAGE', $language_array['#']);
?>

JonnyH
July 8th, 2008, 16:37
Both don't work. Why don't you only put one in there like your supposed to. Detemine the language before entered.

iBrightDev
July 8th, 2008, 16:39
determine the language before, and set a variable like Jonny is saying, then you wont have any problems.

Dynash
July 8th, 2008, 16:40
I think I know the easiest way to do it.
Just create a language directory, and have the languages in seperate folders, and the user just enters the language they want.

JonnyH
July 8th, 2008, 16:46
I think I know the easiest way to do it.
Just create a language directory, and have the languages in seperate folders, and the user just enters the language they want.
You've got the idea...
You could just have them as files not folders, unless you have one or more file for a language.

krakjoe
July 8th, 2008, 16:49
constants can be resources or scalar values, that's it ...

might be neat to detect their language automagically with geoip or something similar ...

iBrightDev
July 8th, 2008, 17:06
constants can be resources or scalar values, that's it ...

might be neat to detect their language automagically with geoip or something similar ...

best idea yet.
http://php.net/geoip
seems like a pretty good way to go.

Dynash
July 8th, 2008, 17:23
ahh, that sounds good. thanks :D

krakjoe
July 8th, 2008, 17:47
you know, you'll still have to give a way for users to change their language, because you have to think about tourists and people who access the internet on the move, on airplanes and what not ( can you do that ?? ), and also just residents of countries who do not speak the native language like in this country a vast amount of people only speak urdu, or arabic ... allow for that ...

you want some code to start you off or will you be alright implementing it yourself ?

Dynash
July 8th, 2008, 18:07
Yeah, I'd have the language settings for users stored inside the mySQL database, but the main language of the script would be defined in the config file. I'll be able to do it myself, thanks though Joe :D