SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Get error when i try this function

    Hi,

    This is the function used in this tutorial at PHP Builder called Localizing a Web Page for Different Languages at phpbuilder.com/columns/white-eisenhamer20060915.php3?aid=1222 I contacted them but am still waiting for an answer..

    The function is this:

    Code:
    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;
    }
    and this is the error i get when i run the file that it is in:

    Parse error: syntax error, unexpected T_FUNCTION in language.php on line 37

    I run PHP4 with MAMP locally..

    Andrew

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Hi Andrew and welcome to the forums

    I assume that line 37 is:
    PHP Code:
    function switch_language_options() { 
    which means that teh problem is BEFORE that line.

    What have you got above that function?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Actually dont worry about posting your code, I had a quick look at the tutorial and there is a parse error:
    PHP Code:
    // Now include the appropriate language file:
    require_once "{$lang}.php" 
    should be
    PHP Code:
    // Now include the appropriate language file:
    require_once "{$lang}.php"
    note the ; at the end of the line.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  4. #4
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a lot, now it runs the page where i include language.php, but i get an error where i call the function. It says:

    Code:
    Fatal error: Call to undefined function: http_build_query() in language.php on line 55
    Its the line that has
    Code:
    http_build_query($get)
    in the function from before...

  5. #5
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    http_build_query is PHP5 specific. With the error message I would say that you are using PHP 4.x....

    add the following code to your language.php file.
    PHP Code:
    if (!function_exists('http_build_query')) {
    function 
    http_build_query($data$prefix=''$sep=''$key='') {
        
    $ret = array();
        foreach ((array)
    $data as $k => $v) {
            if (
    is_int($k) && $prefix != null$k urlencode($prefix $k);
            if (!empty(
    $key)) $k $key.'['.urlencode($k).']';
           
            if (
    is_array($v) || is_object($v))
                
    array_push($rethttp_build_query($v''$sep$k));
            else    
    array_push($ret$k.'='.urlencode($v));
        }

        if (empty(
    $sep)) $sep ini_get('arg_separator.output');
        return 
    implode($sep$ret);
    }} 
    http://us2.php.net/manual/en/functio...uery.php#71677
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  6. #6
    SitePoint Member
    Join Date
    Jun 2008
    Posts
    20
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That did it,

    I am running PHP4 locally..

    Thanks a lot,

  7. #7
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,806
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    No problem Andrew, any other questions or queries just post
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •