language detection
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
<?php
/*
Script Name: Full Operating system language detection
Author: Harald Hope, Website: http://techpatterns.com/
Script Source URI: http://techpatterns.com/downloads/php_language_detection.php
Version 0.3.6
Copyright (C) 8 December 2008
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Get the full text of the GPL here: http://www.gnu.org/licenses/gpl.txt
Coding conventions:
http://cvs.sourceforge.net/viewcvs.py/phpbb/phpBB2/docs/codingstandards.htm?rev=1.3
*/
/*
Changes:
0.3.6 - added possible $feature values to comment header section
*/
/******************************************
Script is currently set to accept 2 parameters, triggered by $feature value.
for example, get_languages( 'data' ):
1. 'header' - sets header values, for redirects etc. No data is returned
2. 'data' - for language data handling, ie for stats, etc.
Returns an array of the following 4 item array for each language the os supports:
1. full language abbreviation, like en-ca
2. primary language, like en
3. full language string, like English (Canada)
4. primary language string, like English
*******************************************/
// choice of redirection header or just getting language data
// to call this you only need to use the $feature parameter
function get_languages( $feature, $spare='' )
{
// get the languages
$a_languages = languages();
$index = '';
$complete = '';
$found = false;// set to default value
//prepare user language array
$user_languages = array();
//check to see if language is set
if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) )
{
$languages = strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"] );
// $languages = ' fr-ch;q=0.3, da, en-us;q=0.8, en;q=0.5, fr;q=0.3';
// need to remove spaces from strings to avoid error
$languages = str_replace( ' ', '', $languages );
$languages = explode( ",", $languages );
//$languages = explode( ",", $test);// this is for testing purposes only
foreach ( $languages as $language_list )
{
// pull out the language, place languages into array of full and primary
// string structure:
$temp_array = array();
// slice out the part before ; on first step, the part before - on second, place into array
$temp_array[0] = substr( $language_list, 0, strcspn( $language_list, ';' ) );//full language
$temp_array[1] = substr( $language_list, 0, 2 );// cut out primary language
//place this array into main $user_languages language array
$user_languages[] = $temp_array;
}
//start going through each one
for ( $i = 0; $i < count( $user_languages ); $i++ )
{
foreach ( $a_languages as $index => $complete )
{
if ( $index == $user_languages[$i][0] )
{
// complete language, like english (canada)
$user_languages[$i][2] = $complete;
// extract working language, like english
$user_languages[$i][3] = substr( $complete, 0, strcspn( $complete, ' (' ) );
}
}
}
}
else// if no languages found
{
$user_languages[0] = array( '','','','' ); //return blank array.
}
// print_r($user_languages);
// return parameters
if ( $feature == 'data' )
{
return $user_languages;
}
// this is just a sample, replace target language and file names with your own.
elseif ( $feature == 'header' )
{
switch ( $user_languages[0][1] )// get default primary language, the first one in array that is
{
case 'en':
$location = 'english.php';
$found = true;
break;
case 'sp':
$location = 'spanish.php';
$found = true;
break;
default:
break;
}
if ( $found )
{
header("Location: $location");
}
else// make sure you have a default page to send them to
{
header("Location: default.php");
}
}
}
function languages()
{
// pack abbreviation/language array
// important note: you must have the default language as the last item in each major language, after all the
// en-ca type entries, so en would be last in that case
$a_languages = array(
'af' => 'Afrikaans',
'sq' => 'Albanian',
'ar-dz' => 'Arabic (Algeria)',
'ar-bh' => 'Arabic (Bahrain)',
'ar-eg' => 'Arabic (Egypt)',
'ar-iq' => 'Arabic (Iraq)',
'ar-jo' => 'Arabic (Jordan)',
'ar-kw' => 'Arabic (Kuwait)',
'ar-lb' => 'Arabic (Lebanon)',
'ar-ly' => 'Arabic (libya)',
'ar-ma' => 'Arabic (Morocco)',
'ar-om' => 'Arabic (Oman)',
'ar-qa' => 'Arabic (Qatar)',
'ar-sa' => 'Arabic (Saudi Arabia)',
'ar-sy' => 'Arabic (Syria)',
'ar-tn' => 'Arabic (Tunisia)',
'ar-ae' => 'Arabic (U.A.E.)',
'ar-ye' => 'Arabic (Yemen)',
'ar' => 'Arabic',
'hy' => 'Armenian',
'as' => 'Assamese',
'az' => 'Azeri',
'eu' => 'Basque',
'be' => 'Belarusian',
'bn' => 'Bengali',
'bg' => 'Bulgarian',
'ca' => 'Catalan',
'zh-cn' => 'Chinese (China)',
'zh-hk' => 'Chinese (Hong Kong SAR)',
'zh-mo' => 'Chinese (Macau SAR)',
'zh-sg' => 'Chinese (Singapore)',
'zh-tw' => 'Chinese (Taiwan)',
'zh' => 'Chinese',
'hr' => 'Croatian',
'cs' => 'Czech',
'da' => 'Danish',
'div' => 'Divehi',
'nl-be' => 'Dutch (Belgium)',
'nl' => 'Dutch (Netherlands)',
'en-au' => 'English (Australia)',
'en-bz' => 'English (Belize)',
'en-ca' => 'English (Canada)',
'en-ie' => 'English (Ireland)',
'en-jm' => 'English (Jamaica)',
'en-nz' => 'English (New Zealand)',
'en-ph' => 'English (Philippines)',
'en-za' => 'English (South Africa)',
'en-tt' => 'English (Trinidad)',
'en-gb' => 'English (United Kingdom)',
'en-us' => 'English (United States)',
'en-zw' => 'English (Zimbabwe)',
'en' => 'English',
'us' => 'English (United States)',
'et' => 'Estonian',
'fo' => 'Faeroese',
'fa' => 'Farsi',
'fi' => 'Finnish',
'fr-be' => 'French (Belgium)',
'fr-ca' => 'French (Canada)',
'fr-lu' => 'French (Luxembourg)',
'fr-mc' => 'French (Monaco)',
'fr-ch' => 'French (Switzerland)',
'fr' => 'French (France)',
'mk' => 'FYRO Macedonian',
'gd' => 'Gaelic',
'ka' => 'Georgian',
'de-at' => 'German (Austria)',
'de-li' => 'German (Liechtenstein)',
'de-lu' => 'German (Luxembourg)',
'de-ch' => 'German (Switzerland)',
'de' => 'German (Germany)',
'el' => 'Greek',
'gu' => 'Gujarati',
'he' => 'Hebrew',
'hi' => 'Hindi',
'hu' => 'Hungarian',
'is' => 'Icelandic',
'id' => 'Indonesian',
'it-ch' => 'Italian (Switzerland)',
'it' => 'Italian (Italy)',
'ja' => 'Japanese',
'kn' => 'Kannada',
'kk' => 'Kazakh',
'kok' => 'Konkani',
'ko' => 'Korean',
'kz' => 'Kyrgyz',
'lv' => 'Latvian',
'lt' => 'Lithuanian',
'ms' => 'Malay',
'ml' => 'Malayalam',
'mt' => 'Maltese',
'mr' => 'Marathi',
'mn' => 'Mongolian (Cyrillic)',
'ne' => 'Nepali (India)',
'nb-no' => 'Norwegian (Bokmal)',
'nn-no' => 'Norwegian (Nynorsk)',
'no' => 'Norwegian (Bokmal)',
'or' => 'Oriya',
'pl' => 'Polish',
'pt-br' => 'Portuguese (Brazil)',
'pt' => 'Portuguese (Portugal)',
'pa' => 'Punjabi',
'rm' => 'Rhaeto-Romanic',
'ro-md' => 'Romanian (Moldova)',
'ro' => 'Romanian',
'ru-md' => 'Russian (Moldova)',
'ru' => 'Russian',
'sa' => 'Sanskrit',
'sr' => 'Serbian',
'sk' => 'Slovak',
'ls' => 'Slovenian',
'sb' => 'Sorbian',
'es-ar' => 'Spanish (Argentina)',
'es-bo' => 'Spanish (Bolivia)',
'es-cl' => 'Spanish (Chile)',
'es-co' => 'Spanish (Colombia)',
'es-cr' => 'Spanish (Costa Rica)',
'es-do' => 'Spanish (Dominican Republic)',
'es-ec' => 'Spanish (Ecuador)',
'es-sv' => 'Spanish (El Salvador)',
'es-gt' => 'Spanish (Guatemala)',
'es-hn' => 'Spanish (Honduras)',
'es-mx' => 'Spanish (Mexico)',
'es-ni' => 'Spanish (Nicaragua)',
'es-pa' => 'Spanish (Panama)',
'es-py' => 'Spanish (Paraguay)',
'es-pe' => 'Spanish (Peru)',
'es-pr' => 'Spanish (Puerto Rico)',
'es-us' => 'Spanish (United States)',
'es-uy' => 'Spanish (Uruguay)',
'es-ve' => 'Spanish (Venezuela)',
'es' => 'Spanish (Traditional Sort)',
'sx' => 'Sutu',
'sw' => 'Swahili',
'sv-fi' => 'Swedish (Finland)',
'sv' => 'Swedish',
'syr' => 'Syriac',
'ta' => 'Tamil',
'tt' => 'Tatar',
'te' => 'Telugu',
'th' => 'Thai',
'ts' => 'Tsonga',
'tn' => 'Tswana',
'tr' => 'Turkish',
'uk' => 'Ukrainian',
'ur' => 'Urdu',
'uz' => 'Uzbek',
'vi' => 'Vietnamese',
'xh' => 'Xhosa',
'yi' => 'Yiddish',
'zu' => 'Zulu' );
return $a_languages;
}
?>
/*
Script Name: Full Operating system language detection
Author: Harald Hope, Website: http://techpatterns.com/
Script Source URI: http://techpatterns.com/downloads/php_language_detection.php
Version 0.3.6
Copyright (C) 8 December 2008
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Get the full text of the GPL here: http://www.gnu.org/licenses/gpl.txt
Coding conventions:
http://cvs.sourceforge.net/viewcvs.py/phpbb/phpBB2/docs/codingstandards.htm?rev=1.3
*/
/*
Changes:
0.3.6 - added possible $feature values to comment header section
*/
/******************************************
Script is currently set to accept 2 parameters, triggered by $feature value.
for example, get_languages( 'data' ):
1. 'header' - sets header values, for redirects etc. No data is returned
2. 'data' - for language data handling, ie for stats, etc.
Returns an array of the following 4 item array for each language the os supports:
1. full language abbreviation, like en-ca
2. primary language, like en
3. full language string, like English (Canada)
4. primary language string, like English
*******************************************/
// choice of redirection header or just getting language data
// to call this you only need to use the $feature parameter
function get_languages( $feature, $spare='' )
{
// get the languages
$a_languages = languages();
$index = '';
$complete = '';
$found = false;// set to default value
//prepare user language array
$user_languages = array();
//check to see if language is set
if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) )
{
$languages = strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"] );
// $languages = ' fr-ch;q=0.3, da, en-us;q=0.8, en;q=0.5, fr;q=0.3';
// need to remove spaces from strings to avoid error
$languages = str_replace( ' ', '', $languages );
$languages = explode( ",", $languages );
//$languages = explode( ",", $test);// this is for testing purposes only
foreach ( $languages as $language_list )
{
// pull out the language, place languages into array of full and primary
// string structure:
$temp_array = array();
// slice out the part before ; on first step, the part before - on second, place into array
$temp_array[0] = substr( $language_list, 0, strcspn( $language_list, ';' ) );//full language
$temp_array[1] = substr( $language_list, 0, 2 );// cut out primary language
//place this array into main $user_languages language array
$user_languages[] = $temp_array;
}
//start going through each one
for ( $i = 0; $i < count( $user_languages ); $i++ )
{
foreach ( $a_languages as $index => $complete )
{
if ( $index == $user_languages[$i][0] )
{
// complete language, like english (canada)
$user_languages[$i][2] = $complete;
// extract working language, like english
$user_languages[$i][3] = substr( $complete, 0, strcspn( $complete, ' (' ) );
}
}
}
}
else// if no languages found
{
$user_languages[0] = array( '','','','' ); //return blank array.
}
// print_r($user_languages);
// return parameters
if ( $feature == 'data' )
{
return $user_languages;
}
// this is just a sample, replace target language and file names with your own.
elseif ( $feature == 'header' )
{
switch ( $user_languages[0][1] )// get default primary language, the first one in array that is
{
case 'en':
$location = 'english.php';
$found = true;
break;
case 'sp':
$location = 'spanish.php';
$found = true;
break;
default:
break;
}
if ( $found )
{
header("Location: $location");
}
else// make sure you have a default page to send them to
{
header("Location: default.php");
}
}
}
function languages()
{
// pack abbreviation/language array
// important note: you must have the default language as the last item in each major language, after all the
// en-ca type entries, so en would be last in that case
$a_languages = array(
'af' => 'Afrikaans',
'sq' => 'Albanian',
'ar-dz' => 'Arabic (Algeria)',
'ar-bh' => 'Arabic (Bahrain)',
'ar-eg' => 'Arabic (Egypt)',
'ar-iq' => 'Arabic (Iraq)',
'ar-jo' => 'Arabic (Jordan)',
'ar-kw' => 'Arabic (Kuwait)',
'ar-lb' => 'Arabic (Lebanon)',
'ar-ly' => 'Arabic (libya)',
'ar-ma' => 'Arabic (Morocco)',
'ar-om' => 'Arabic (Oman)',
'ar-qa' => 'Arabic (Qatar)',
'ar-sa' => 'Arabic (Saudi Arabia)',
'ar-sy' => 'Arabic (Syria)',
'ar-tn' => 'Arabic (Tunisia)',
'ar-ae' => 'Arabic (U.A.E.)',
'ar-ye' => 'Arabic (Yemen)',
'ar' => 'Arabic',
'hy' => 'Armenian',
'as' => 'Assamese',
'az' => 'Azeri',
'eu' => 'Basque',
'be' => 'Belarusian',
'bn' => 'Bengali',
'bg' => 'Bulgarian',
'ca' => 'Catalan',
'zh-cn' => 'Chinese (China)',
'zh-hk' => 'Chinese (Hong Kong SAR)',
'zh-mo' => 'Chinese (Macau SAR)',
'zh-sg' => 'Chinese (Singapore)',
'zh-tw' => 'Chinese (Taiwan)',
'zh' => 'Chinese',
'hr' => 'Croatian',
'cs' => 'Czech',
'da' => 'Danish',
'div' => 'Divehi',
'nl-be' => 'Dutch (Belgium)',
'nl' => 'Dutch (Netherlands)',
'en-au' => 'English (Australia)',
'en-bz' => 'English (Belize)',
'en-ca' => 'English (Canada)',
'en-ie' => 'English (Ireland)',
'en-jm' => 'English (Jamaica)',
'en-nz' => 'English (New Zealand)',
'en-ph' => 'English (Philippines)',
'en-za' => 'English (South Africa)',
'en-tt' => 'English (Trinidad)',
'en-gb' => 'English (United Kingdom)',
'en-us' => 'English (United States)',
'en-zw' => 'English (Zimbabwe)',
'en' => 'English',
'us' => 'English (United States)',
'et' => 'Estonian',
'fo' => 'Faeroese',
'fa' => 'Farsi',
'fi' => 'Finnish',
'fr-be' => 'French (Belgium)',
'fr-ca' => 'French (Canada)',
'fr-lu' => 'French (Luxembourg)',
'fr-mc' => 'French (Monaco)',
'fr-ch' => 'French (Switzerland)',
'fr' => 'French (France)',
'mk' => 'FYRO Macedonian',
'gd' => 'Gaelic',
'ka' => 'Georgian',
'de-at' => 'German (Austria)',
'de-li' => 'German (Liechtenstein)',
'de-lu' => 'German (Luxembourg)',
'de-ch' => 'German (Switzerland)',
'de' => 'German (Germany)',
'el' => 'Greek',
'gu' => 'Gujarati',
'he' => 'Hebrew',
'hi' => 'Hindi',
'hu' => 'Hungarian',
'is' => 'Icelandic',
'id' => 'Indonesian',
'it-ch' => 'Italian (Switzerland)',
'it' => 'Italian (Italy)',
'ja' => 'Japanese',
'kn' => 'Kannada',
'kk' => 'Kazakh',
'kok' => 'Konkani',
'ko' => 'Korean',
'kz' => 'Kyrgyz',
'lv' => 'Latvian',
'lt' => 'Lithuanian',
'ms' => 'Malay',
'ml' => 'Malayalam',
'mt' => 'Maltese',
'mr' => 'Marathi',
'mn' => 'Mongolian (Cyrillic)',
'ne' => 'Nepali (India)',
'nb-no' => 'Norwegian (Bokmal)',
'nn-no' => 'Norwegian (Nynorsk)',
'no' => 'Norwegian (Bokmal)',
'or' => 'Oriya',
'pl' => 'Polish',
'pt-br' => 'Portuguese (Brazil)',
'pt' => 'Portuguese (Portugal)',
'pa' => 'Punjabi',
'rm' => 'Rhaeto-Romanic',
'ro-md' => 'Romanian (Moldova)',
'ro' => 'Romanian',
'ru-md' => 'Russian (Moldova)',
'ru' => 'Russian',
'sa' => 'Sanskrit',
'sr' => 'Serbian',
'sk' => 'Slovak',
'ls' => 'Slovenian',
'sb' => 'Sorbian',
'es-ar' => 'Spanish (Argentina)',
'es-bo' => 'Spanish (Bolivia)',
'es-cl' => 'Spanish (Chile)',
'es-co' => 'Spanish (Colombia)',
'es-cr' => 'Spanish (Costa Rica)',
'es-do' => 'Spanish (Dominican Republic)',
'es-ec' => 'Spanish (Ecuador)',
'es-sv' => 'Spanish (El Salvador)',
'es-gt' => 'Spanish (Guatemala)',
'es-hn' => 'Spanish (Honduras)',
'es-mx' => 'Spanish (Mexico)',
'es-ni' => 'Spanish (Nicaragua)',
'es-pa' => 'Spanish (Panama)',
'es-py' => 'Spanish (Paraguay)',
'es-pe' => 'Spanish (Peru)',
'es-pr' => 'Spanish (Puerto Rico)',
'es-us' => 'Spanish (United States)',
'es-uy' => 'Spanish (Uruguay)',
'es-ve' => 'Spanish (Venezuela)',
'es' => 'Spanish (Traditional Sort)',
'sx' => 'Sutu',
'sw' => 'Swahili',
'sv-fi' => 'Swedish (Finland)',
'sv' => 'Swedish',
'syr' => 'Syriac',
'ta' => 'Tamil',
'tt' => 'Tatar',
'te' => 'Telugu',
'th' => 'Thai',
'ts' => 'Tsonga',
'tn' => 'Tswana',
'tr' => 'Turkish',
'uk' => 'Ukrainian',
'ur' => 'Urdu',
'uz' => 'Uzbek',
'vi' => 'Vietnamese',
'xh' => 'Xhosa',
'yi' => 'Yiddish',
'zu' => 'Zulu' );
return $a_languages;
}
?>
hulp zou zeer gewaardeerd worden...
Array
(
[0] => Array
(
[0] => nl
[1] => nl
[2] => Dutch (Netherlands)
[3] => Dutch
)
)
In Firefox:
Array
(
[0] => Array
(
[0] => nl
[1] => nl
[2] => Dutch (Netherlands)
[3] => Dutch
)
[1] => Array
(
[0] => en-us
[1] => en
[2] => English (United States)
[3] => English
)
[2] => Array
(
[0] => en
[1] => en
[2] => English
[3] => English
)
)
Alleen nu he volgende, hoe kan ik de header functie van het script gebruiken om mij te laten doorverwijzen naar ingesteld pagina's
en deze functie:
get_languages( $feature, $spare='' )
aanroepen met #feature = 'header'
Ik snap gewoon helemaal niks van Arrays
Code (php)
1
2
3
4
2
3
4
<?php
include('het pad en de naam naar het script wat je hierboven hebt gepost');
get_languages('header');
?>
include('het pad en de naam naar het script wat je hierboven hebt gepost');
get_languages('header');
?>
dat is alles!
in plaats van de regel waar de include staat kan je ook gewoon het hele script plakken.
je wilt toch doorverwezen worden naar andere pagina's ?
"Ik heb hier een gratis script voor gevonden maar ik krijg het met geen mogelijk werken, ik kan geen enkele waarde uit het script met een echo laten neerschrijven."
dan hoef je dus ook niks te echo-en
zelf pagina's toevoegen of wijzigen gaat zo:
dat ze je dus wel ff op de goede plaats bij regel 105 ofzo.
regel 122 bepaald de plaats van de standaard pagina als je geen aparte pagina voor de taal hebt
Warning: Cannot modify header information - headers already sent by (output started at /home/httpd/vhosts/dannyvanderzande.nl/httpdocs/site/test/test.php:288) in /home/httpd/vhosts/dannyvanderzande.nl/httpdocs/site/test/test.php on line 120
line 120 is de header naar de $location variabele
en
line 288 is de eindtag van het PHP script
enig idee wat ik foutdoe.
Zal beide code's even posten
index:
test.php:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
<?php
/*
Script Name: Full Operating system language detection
Author: Harald Hope, Website: http://techpatterns.com/
Script Source URI: http://techpatterns.com/downloads/php_language_detection.php
Version 0.3.6
Copyright (C) 8 December 2008
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Get the full text of the GPL here: http://www.gnu.org/licenses/gpl.txt
Coding conventions:
http://cvs.sourceforge.net/viewcvs.py/phpbb/phpBB2/docs/codingstandards.htm?rev=1.3
*/
/*
Changes:
0.3.6 - added possible $feature values to comment header section
*/
/******************************************
Script is currently set to accept 2 parameters, triggered by $feature value.
for example, get_languages( 'data' ):
1. 'header' - sets header values, for redirects etc. No data is returned
2. 'data' - for language data handling, ie for stats, etc.
Returns an array of the following 4 item array for each language the os supports:
1. full language abbreviation, like en-ca
2. primary language, like en
3. full language string, like English (Canada)
4. primary language string, like English
*******************************************/
// choice of redirection header or just getting language data
// to call this you only need to use the $feature parameter
function get_languages( $feature, $spare='' )
{
// get the languages
$a_languages = languages();
$index = '';
$complete = '';
$found = false;// set to default value
//prepare user language array
$user_languages = array();
//check to see if language is set
if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) )
{
$languages = strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"] );
// $languages = ' fr-ch;q=0.3, da, en-us;q=0.8, en;q=0.5, fr;q=0.3';
// need to remove spaces from strings to avoid error
$languages = str_replace( ' ', '', $languages );
$languages = explode( ",", $languages );
//$languages = explode( ",", $test);// this is for testing purposes only
foreach ( $languages as $language_list )
{
// pull out the language, place languages into array of full and primary
// string structure:
$temp_array = array();
// slice out the part before ; on first step, the part before - on second, place into array
$temp_array[0] = substr( $language_list, 0, strcspn( $language_list, ';' ) );//full language
$temp_array[1] = substr( $language_list, 0, 2 );// cut out primary language
//place this array into main $user_languages language array
$user_languages[] = $temp_array;
}
//start going through each one
for ( $i = 0; $i < count( $user_languages ); $i++ )
{
foreach ( $a_languages as $index => $complete )
{
if ( $index == $user_languages[$i][0] )
{
// complete language, like english (canada)
$user_languages[$i][2] = $complete;
// extract working language, like english
$user_languages[$i][3] = substr( $complete, 0, strcspn( $complete, ' (' ) );
}
}
}
}
else// if no languages found
{
$user_languages[0] = array( '','','','' ); //return blank array.
}
// print_r($user_languages);
// return parameters
if ( $feature == 'data' )
{
return $user_languages;
}
// this is just a sample, replace target language and file names with your own.
elseif ( $feature == 'header' )
{
switch ( $user_languages[0][1] )// get default primary language, the first one in array that is
{
case 'en':
$location = 'english.php';
$found = true;
break;
case 'nl':
$location = 'nederlands.html';
$found = true;
break;
default:
$location = 'english.php';
$found = true;
break;
}
if ( $found )
{
header ("Location: $location");
}
else// make sure you have a default page to send them to
{
header("Location: english.php");
}
}
}
function languages()
{
// pack abbreviation/language array
// important note: you must have the default language as the last item in each major language, after all the
// en-ca type entries, so en would be last in that case
$a_languages = array(
'af' => 'Afrikaans',
'sq' => 'Albanian',
'ar-dz' => 'Arabic (Algeria)',
'ar-bh' => 'Arabic (Bahrain)',
'ar-eg' => 'Arabic (Egypt)',
'ar-iq' => 'Arabic (Iraq)',
'ar-jo' => 'Arabic (Jordan)',
'ar-kw' => 'Arabic (Kuwait)',
'ar-lb' => 'Arabic (Lebanon)',
'ar-ly' => 'Arabic (libya)',
'ar-ma' => 'Arabic (Morocco)',
'ar-om' => 'Arabic (Oman)',
'ar-qa' => 'Arabic (Qatar)',
'ar-sa' => 'Arabic (Saudi Arabia)',
'ar-sy' => 'Arabic (Syria)',
'ar-tn' => 'Arabic (Tunisia)',
'ar-ae' => 'Arabic (U.A.E.)',
'ar-ye' => 'Arabic (Yemen)',
'ar' => 'Arabic',
'hy' => 'Armenian',
'as' => 'Assamese',
'az' => 'Azeri',
'eu' => 'Basque',
'be' => 'Belarusian',
'bn' => 'Bengali',
'bg' => 'Bulgarian',
'ca' => 'Catalan',
'zh-cn' => 'Chinese (China)',
'zh-hk' => 'Chinese (Hong Kong SAR)',
'zh-mo' => 'Chinese (Macau SAR)',
'zh-sg' => 'Chinese (Singapore)',
'zh-tw' => 'Chinese (Taiwan)',
'zh' => 'Chinese',
'hr' => 'Croatian',
'cs' => 'Czech',
'da' => 'Danish',
'div' => 'Divehi',
'nl-be' => 'Dutch (Belgium)',
'nl' => 'Dutch (Netherlands)',
'en-au' => 'English (Australia)',
'en-bz' => 'English (Belize)',
'en-ca' => 'English (Canada)',
'en-ie' => 'English (Ireland)',
'en-jm' => 'English (Jamaica)',
'en-nz' => 'English (New Zealand)',
'en-ph' => 'English (Philippines)',
'en-za' => 'English (South Africa)',
'en-tt' => 'English (Trinidad)',
'en-gb' => 'English (United Kingdom)',
'en-us' => 'English (United States)',
'en-zw' => 'English (Zimbabwe)',
'en' => 'English',
'us' => 'English (United States)',
'et' => 'Estonian',
'fo' => 'Faeroese',
'fa' => 'Farsi',
'fi' => 'Finnish',
'fr-be' => 'French (Belgium)',
'fr-ca' => 'French (Canada)',
'fr-lu' => 'French (Luxembourg)',
'fr-mc' => 'French (Monaco)',
'fr-ch' => 'French (Switzerland)',
'fr' => 'French (France)',
'mk' => 'FYRO Macedonian',
'gd' => 'Gaelic',
'ka' => 'Georgian',
'de-at' => 'German (Austria)',
'de-li' => 'German (Liechtenstein)',
'de-lu' => 'German (Luxembourg)',
'de-ch' => 'German (Switzerland)',
'de' => 'German (Germany)',
'el' => 'Greek',
'gu' => 'Gujarati',
'he' => 'Hebrew',
'hi' => 'Hindi',
'hu' => 'Hungarian',
'is' => 'Icelandic',
'id' => 'Indonesian',
'it-ch' => 'Italian (Switzerland)',
'it' => 'Italian (Italy)',
'ja' => 'Japanese',
'kn' => 'Kannada',
'kk' => 'Kazakh',
'kok' => 'Konkani',
'ko' => 'Korean',
'kz' => 'Kyrgyz',
'lv' => 'Latvian',
'lt' => 'Lithuanian',
'ms' => 'Malay',
'ml' => 'Malayalam',
'mt' => 'Maltese',
'mr' => 'Marathi',
'mn' => 'Mongolian (Cyrillic)',
'ne' => 'Nepali (India)',
'nb-no' => 'Norwegian (Bokmal)',
'nn-no' => 'Norwegian (Nynorsk)',
'no' => 'Norwegian (Bokmal)',
'or' => 'Oriya',
'pl' => 'Polish',
'pt-br' => 'Portuguese (Brazil)',
'pt' => 'Portuguese (Portugal)',
'pa' => 'Punjabi',
'rm' => 'Rhaeto-Romanic',
'ro-md' => 'Romanian (Moldova)',
'ro' => 'Romanian',
'ru-md' => 'Russian (Moldova)',
'ru' => 'Russian',
'sa' => 'Sanskrit',
'sr' => 'Serbian',
'sk' => 'Slovak',
'ls' => 'Slovenian',
'sb' => 'Sorbian',
'es-ar' => 'Spanish (Argentina)',
'es-bo' => 'Spanish (Bolivia)',
'es-cl' => 'Spanish (Chile)',
'es-co' => 'Spanish (Colombia)',
'es-cr' => 'Spanish (Costa Rica)',
'es-do' => 'Spanish (Dominican Republic)',
'es-ec' => 'Spanish (Ecuador)',
'es-sv' => 'Spanish (El Salvador)',
'es-gt' => 'Spanish (Guatemala)',
'es-hn' => 'Spanish (Honduras)',
'es-mx' => 'Spanish (Mexico)',
'es-ni' => 'Spanish (Nicaragua)',
'es-pa' => 'Spanish (Panama)',
'es-py' => 'Spanish (Paraguay)',
'es-pe' => 'Spanish (Peru)',
'es-pr' => 'Spanish (Puerto Rico)',
'es-us' => 'Spanish (United States)',
'es-uy' => 'Spanish (Uruguay)',
'es-ve' => 'Spanish (Venezuela)',
'es' => 'Spanish (Traditional Sort)',
'sx' => 'Sutu',
'sw' => 'Swahili',
'sv-fi' => 'Swedish (Finland)',
'sv' => 'Swedish',
'syr' => 'Syriac',
'ta' => 'Tamil',
'tt' => 'Tatar',
'te' => 'Telugu',
'th' => 'Thai',
'ts' => 'Tsonga',
'tn' => 'Tswana',
'tr' => 'Turkish',
'uk' => 'Ukrainian',
'ur' => 'Urdu',
'uz' => 'Uzbek',
'vi' => 'Vietnamese',
'xh' => 'Xhosa',
'yi' => 'Yiddish',
'zu' => 'Zulu' );
return $a_languages;
}
?>
/*
Script Name: Full Operating system language detection
Author: Harald Hope, Website: http://techpatterns.com/
Script Source URI: http://techpatterns.com/downloads/php_language_detection.php
Version 0.3.6
Copyright (C) 8 December 2008
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Get the full text of the GPL here: http://www.gnu.org/licenses/gpl.txt
Coding conventions:
http://cvs.sourceforge.net/viewcvs.py/phpbb/phpBB2/docs/codingstandards.htm?rev=1.3
*/
/*
Changes:
0.3.6 - added possible $feature values to comment header section
*/
/******************************************
Script is currently set to accept 2 parameters, triggered by $feature value.
for example, get_languages( 'data' ):
1. 'header' - sets header values, for redirects etc. No data is returned
2. 'data' - for language data handling, ie for stats, etc.
Returns an array of the following 4 item array for each language the os supports:
1. full language abbreviation, like en-ca
2. primary language, like en
3. full language string, like English (Canada)
4. primary language string, like English
*******************************************/
// choice of redirection header or just getting language data
// to call this you only need to use the $feature parameter
function get_languages( $feature, $spare='' )
{
// get the languages
$a_languages = languages();
$index = '';
$complete = '';
$found = false;// set to default value
//prepare user language array
$user_languages = array();
//check to see if language is set
if ( isset( $_SERVER["HTTP_ACCEPT_LANGUAGE"] ) )
{
$languages = strtolower( $_SERVER["HTTP_ACCEPT_LANGUAGE"] );
// $languages = ' fr-ch;q=0.3, da, en-us;q=0.8, en;q=0.5, fr;q=0.3';
// need to remove spaces from strings to avoid error
$languages = str_replace( ' ', '', $languages );
$languages = explode( ",", $languages );
//$languages = explode( ",", $test);// this is for testing purposes only
foreach ( $languages as $language_list )
{
// pull out the language, place languages into array of full and primary
// string structure:
$temp_array = array();
// slice out the part before ; on first step, the part before - on second, place into array
$temp_array[0] = substr( $language_list, 0, strcspn( $language_list, ';' ) );//full language
$temp_array[1] = substr( $language_list, 0, 2 );// cut out primary language
//place this array into main $user_languages language array
$user_languages[] = $temp_array;
}
//start going through each one
for ( $i = 0; $i < count( $user_languages ); $i++ )
{
foreach ( $a_languages as $index => $complete )
{
if ( $index == $user_languages[$i][0] )
{
// complete language, like english (canada)
$user_languages[$i][2] = $complete;
// extract working language, like english
$user_languages[$i][3] = substr( $complete, 0, strcspn( $complete, ' (' ) );
}
}
}
}
else// if no languages found
{
$user_languages[0] = array( '','','','' ); //return blank array.
}
// print_r($user_languages);
// return parameters
if ( $feature == 'data' )
{
return $user_languages;
}
// this is just a sample, replace target language and file names with your own.
elseif ( $feature == 'header' )
{
switch ( $user_languages[0][1] )// get default primary language, the first one in array that is
{
case 'en':
$location = 'english.php';
$found = true;
break;
case 'nl':
$location = 'nederlands.html';
$found = true;
break;
default:
$location = 'english.php';
$found = true;
break;
}
if ( $found )
{
header ("Location: $location");
}
else// make sure you have a default page to send them to
{
header("Location: english.php");
}
}
}
function languages()
{
// pack abbreviation/language array
// important note: you must have the default language as the last item in each major language, after all the
// en-ca type entries, so en would be last in that case
$a_languages = array(
'af' => 'Afrikaans',
'sq' => 'Albanian',
'ar-dz' => 'Arabic (Algeria)',
'ar-bh' => 'Arabic (Bahrain)',
'ar-eg' => 'Arabic (Egypt)',
'ar-iq' => 'Arabic (Iraq)',
'ar-jo' => 'Arabic (Jordan)',
'ar-kw' => 'Arabic (Kuwait)',
'ar-lb' => 'Arabic (Lebanon)',
'ar-ly' => 'Arabic (libya)',
'ar-ma' => 'Arabic (Morocco)',
'ar-om' => 'Arabic (Oman)',
'ar-qa' => 'Arabic (Qatar)',
'ar-sa' => 'Arabic (Saudi Arabia)',
'ar-sy' => 'Arabic (Syria)',
'ar-tn' => 'Arabic (Tunisia)',
'ar-ae' => 'Arabic (U.A.E.)',
'ar-ye' => 'Arabic (Yemen)',
'ar' => 'Arabic',
'hy' => 'Armenian',
'as' => 'Assamese',
'az' => 'Azeri',
'eu' => 'Basque',
'be' => 'Belarusian',
'bn' => 'Bengali',
'bg' => 'Bulgarian',
'ca' => 'Catalan',
'zh-cn' => 'Chinese (China)',
'zh-hk' => 'Chinese (Hong Kong SAR)',
'zh-mo' => 'Chinese (Macau SAR)',
'zh-sg' => 'Chinese (Singapore)',
'zh-tw' => 'Chinese (Taiwan)',
'zh' => 'Chinese',
'hr' => 'Croatian',
'cs' => 'Czech',
'da' => 'Danish',
'div' => 'Divehi',
'nl-be' => 'Dutch (Belgium)',
'nl' => 'Dutch (Netherlands)',
'en-au' => 'English (Australia)',
'en-bz' => 'English (Belize)',
'en-ca' => 'English (Canada)',
'en-ie' => 'English (Ireland)',
'en-jm' => 'English (Jamaica)',
'en-nz' => 'English (New Zealand)',
'en-ph' => 'English (Philippines)',
'en-za' => 'English (South Africa)',
'en-tt' => 'English (Trinidad)',
'en-gb' => 'English (United Kingdom)',
'en-us' => 'English (United States)',
'en-zw' => 'English (Zimbabwe)',
'en' => 'English',
'us' => 'English (United States)',
'et' => 'Estonian',
'fo' => 'Faeroese',
'fa' => 'Farsi',
'fi' => 'Finnish',
'fr-be' => 'French (Belgium)',
'fr-ca' => 'French (Canada)',
'fr-lu' => 'French (Luxembourg)',
'fr-mc' => 'French (Monaco)',
'fr-ch' => 'French (Switzerland)',
'fr' => 'French (France)',
'mk' => 'FYRO Macedonian',
'gd' => 'Gaelic',
'ka' => 'Georgian',
'de-at' => 'German (Austria)',
'de-li' => 'German (Liechtenstein)',
'de-lu' => 'German (Luxembourg)',
'de-ch' => 'German (Switzerland)',
'de' => 'German (Germany)',
'el' => 'Greek',
'gu' => 'Gujarati',
'he' => 'Hebrew',
'hi' => 'Hindi',
'hu' => 'Hungarian',
'is' => 'Icelandic',
'id' => 'Indonesian',
'it-ch' => 'Italian (Switzerland)',
'it' => 'Italian (Italy)',
'ja' => 'Japanese',
'kn' => 'Kannada',
'kk' => 'Kazakh',
'kok' => 'Konkani',
'ko' => 'Korean',
'kz' => 'Kyrgyz',
'lv' => 'Latvian',
'lt' => 'Lithuanian',
'ms' => 'Malay',
'ml' => 'Malayalam',
'mt' => 'Maltese',
'mr' => 'Marathi',
'mn' => 'Mongolian (Cyrillic)',
'ne' => 'Nepali (India)',
'nb-no' => 'Norwegian (Bokmal)',
'nn-no' => 'Norwegian (Nynorsk)',
'no' => 'Norwegian (Bokmal)',
'or' => 'Oriya',
'pl' => 'Polish',
'pt-br' => 'Portuguese (Brazil)',
'pt' => 'Portuguese (Portugal)',
'pa' => 'Punjabi',
'rm' => 'Rhaeto-Romanic',
'ro-md' => 'Romanian (Moldova)',
'ro' => 'Romanian',
'ru-md' => 'Russian (Moldova)',
'ru' => 'Russian',
'sa' => 'Sanskrit',
'sr' => 'Serbian',
'sk' => 'Slovak',
'ls' => 'Slovenian',
'sb' => 'Sorbian',
'es-ar' => 'Spanish (Argentina)',
'es-bo' => 'Spanish (Bolivia)',
'es-cl' => 'Spanish (Chile)',
'es-co' => 'Spanish (Colombia)',
'es-cr' => 'Spanish (Costa Rica)',
'es-do' => 'Spanish (Dominican Republic)',
'es-ec' => 'Spanish (Ecuador)',
'es-sv' => 'Spanish (El Salvador)',
'es-gt' => 'Spanish (Guatemala)',
'es-hn' => 'Spanish (Honduras)',
'es-mx' => 'Spanish (Mexico)',
'es-ni' => 'Spanish (Nicaragua)',
'es-pa' => 'Spanish (Panama)',
'es-py' => 'Spanish (Paraguay)',
'es-pe' => 'Spanish (Peru)',
'es-pr' => 'Spanish (Puerto Rico)',
'es-us' => 'Spanish (United States)',
'es-uy' => 'Spanish (Uruguay)',
'es-ve' => 'Spanish (Venezuela)',
'es' => 'Spanish (Traditional Sort)',
'sx' => 'Sutu',
'sw' => 'Swahili',
'sv-fi' => 'Swedish (Finland)',
'sv' => 'Swedish',
'syr' => 'Syriac',
'ta' => 'Tamil',
'tt' => 'Tatar',
'te' => 'Telugu',
'th' => 'Thai',
'ts' => 'Tsonga',
'tn' => 'Tswana',
'tr' => 'Turkish',
'uk' => 'Ukrainian',
'ur' => 'Urdu',
'uz' => 'Uzbek',
'vi' => 'Vietnamese',
'xh' => 'Xhosa',
'yi' => 'Yiddish',
'zu' => 'Zulu' );
return $a_languages;
}
?>
Ja ik weet dat dit komt door dubbele header output maar ik gebruik al sinds jaar en dag dreamweaver voor al mijn scripting en die heeft nog nooit dit probleem gegeven tenzij ik ook echt 2 maal een header heb geoutput of iets van HTML heb laten schrijven voor de header. Helaas zie ik dit keer echt niet wat er mis is gegaan en daarom dus de vraag of iemand anders het wel ziet..
Ik krijg het idee dat er na de ?> een spatie of een lege regel staat.
Er stond een spatie, ik had al aan het idee van een enter zitten denken maar een spatie niet.. best som misschien maar zo te zien werkt het nu wel, hartstikke bedankt, top!