mr_badger Posted April 4, 2007 Share Posted April 4, 2007 I have followed a tutorial word for word but I'm getting this parse error, I know it will be something simple but I need help. // 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) { The problem is the function switch_language_options () { Link to comment https://forums.phpfreaks.com/topic/45636-parse-error-unexpected-t_function/ Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 You need to show us about 10 to 20 lines before the function. It's probably a missing "}" or semi-colon. Ken Link to comment https://forums.phpfreaks.com/topic/45636-parse-error-unexpected-t_function/#findComment-221632 Share on other sites More sharing options...
trq Posted April 4, 2007 Share Posted April 4, 2007 Were going to need more code. There is no syntax errors in what you've posted. Link to comment https://forums.phpfreaks.com/topic/45636-parse-error-unexpected-t_function/#findComment-221634 Share on other sites More sharing options...
mr_badger Posted April 4, 2007 Author Share Posted April 4, 2007 sorry, I will post all the code. <?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; } ?> Link to comment https://forums.phpfreaks.com/topic/45636-parse-error-unexpected-t_function/#findComment-221644 Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 You have an opening "{" on this "if" but no closing "}" <?php if (! (in_array($lang, array_keys($languages)))) { die("ERROR: Bad Language String Provided!"); ?> Actually, you can remove the opening "{" since there is only one line in the statement block that follows the "if". Ken Link to comment https://forums.phpfreaks.com/topic/45636-parse-error-unexpected-t_function/#findComment-221648 Share on other sites More sharing options...
mr_badger Posted April 4, 2007 Author Share Posted April 4, 2007 ok I did that but I'm still getting the original parse error. Link to comment https://forums.phpfreaks.com/topic/45636-parse-error-unexpected-t_function/#findComment-221654 Share on other sites More sharing options...
kenrbnsn Posted April 4, 2007 Share Posted April 4, 2007 There's a missing semi-colon on this line: <?php require_once "{$lang}.php" ?> and there's an extra "}" in this snippet: <?php 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; ?> Ken Link to comment https://forums.phpfreaks.com/topic/45636-parse-error-unexpected-t_function/#findComment-221657 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.