Jump to content
php.lv forumi

Lapa ar vairākām valodām


imop

Recommended Posts

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...