imop Posted May 5, 2009 Report Share Posted May 5, 2009 Cenšos apgūt vairāku valodu funkciju vienā lapā, tamdēļ parakos google un atradu vienu man piemērotu variantu ar kuru varētu darboties, bet visu laiku met ārā vienu problēmu ka nav pareizi definēta funkcija - function switch_language_options() language.php <?php // This is a library, that by including it, // automatically determines the proper language // to use and includes the language file. // First define an array of all possible // languages: $languages = array('en' => 'English', 'fr' => 'French', 'de' => 'German'); // Look at the GET string to see if lang is // specified: if (isset($_GET['lang'])) { // It's been specified, so set the language $lang = $_GET['lang']; // While here, send a cookie to remember this // selection for 1 year. setcookie('lang', $lang, time()+(3600*24*365)); } // Ok, otherwise look for the cookie itself: elseif (isset($_COOKIE['lang'])) { // Use this $lang = $_COOKIE['lang']; } else { // Otherwise, default to English $lang = 'en'; } // Make sure that the language string we have is // a valid one: if (!(in_array($lang, array_keys($languages)))) { die("ERROR: Bad Language String Provided!"); } // Now include the appropriate language file: require_once "{$lang}.php" // As one last step, create a function // that can be used to output language // options to the user: function switch_language_options() { // Include a few globals that we will need: global $text, $languages, $lang; // Start our string with a language specific // 'switch' statement: $retval = $text['switch']; // Loop through all possible languages to // create our options. $get = $_GET; foreach ($languages as $abbrv => $name) { // Create the link, ignoring the current one. if ($abbrv !== $lang) { // Recreate the GET string with // this language. $get['lang'] = $abbrv; $url = $_SERVER['PHP_SELF'] . '?' . http_build_query($get); $retval .= " <a href=\"{$url}\"> {$name}</a>"; } } // Now return this string. return $retval; } ?> HELP! Quote Link to comment Share on other sites More sharing options...
Aleksejs Posted May 5, 2009 Report Share Posted May 5, 2009 Kāds tieši tas paziņojums par nepareizo definēšanu? Quote Link to comment Share on other sites More sharing options...
imop Posted May 5, 2009 Author Report Share Posted May 5, 2009 Kāds tieši tas paziņojums par nepareizo definēšanu? Piemirsu ierakstīt erorr: tad nu: Parse error: syntax error, unexpected T_FUNCTION in /var/www/HOSTINGS/MACIBU/language.php on line 41 Quote Link to comment Share on other sites More sharing options...
xPtv45z Posted May 5, 2009 Report Share Posted May 5, 2009 Te beigās semikola trūkst - require_once "{$lang}.php" Quote Link to comment Share on other sites More sharing options...
imop Posted May 5, 2009 Author Report Share Posted May 5, 2009 Te beigās semikola trūkst - require_once "{$lang}.php" njaa kaa es taa nepamaniiju... Liels paldies! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.