Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Feb 2007
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I'm Stuck... choosing a variable depending on the value of another variable

    Hey Guys,

    I'm stuck on this... I'm trying to use a function to select the right array row. So for instance if I type in :
    PHP Code:
    langText (txt_userpanel_greetingcmn
    I'll want it to read the mandarin row of the $txt_userpanel_greeting array...

    Any clues?

    PHP Code:
    // PAGE TEXT ARRAYS
    $txt_userpanel_greeting['eng'] = "Hey ";
    $txt_userpanel_greeting['cmn'] = "你好 ";
    $txt_userpanel_greeting['tha'] = "สวัสดี ";
    $txt_userpanel_greeting['kor'] = "안녕하세요 ";
    // /PAGE TEXT ARRAYS

    function langText($ftext$flang)
      {
    echo $
    $ftext["$flang"];
      }

    langText(txt_userpanel_greetingeng); 
    Thanks guys... I'm trying to make my website multilingual!

  • #2
    Regular Coder
    Join Date
    Jun 2004
    Posts
    194
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Try this:

    PHP Code:
    <?php

    $txt_userpanel_greeting 
    = array();
    $txt_userpanel_greeting['eng'] = "Hey ";
    $txt_userpanel_greeting['cmn'] = "你好 ";
    $txt_userpanel_greeting['tha'] = "สวัสดี ";
    $txt_userpanel_greeting['kor'] = "안녕하세요 ";

    function 
    langText($ftext$flang) {

        foreach (
    $ftext as $key => $value) {

            if (
    $key == $flang) {
                return 
    $value;

            }

        }

    }

    echo 
    langText($txt_userpanel_greeting"eng");

    ?>

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Just do:
    PHP Code:
    <?php
    $txt_userpanel_greeting 
    = array();
    $txt_userpanel_greeting['eng'] = "Hey ";
    $txt_userpanel_greeting['cmn'] = "你好 ";
    $txt_userpanel_greeting['tha'] = "สวัสดี ";
    $txt_userpanel_greeting['kor'] = "안녕하세요 ";

    function 
    langText($ftext$flang)
    {
        if(!isset(
    $ftext[$flang]))
        {
            
    //error
        
    }
        return 
    $ftext[$flang];
    }

    echo 
    langText($txt_userpanel_greeting"eng");
    ?>
    dumpfi
    "Failure is not an option. It comes bundled with the software."
    ....../)/)..(\__/).(\(\................../)_/)......
    .....(-.-).(='.'=).(-.-)................(o.O)...../<)
    ....(.).(.)("}_("}(.)(.)...............(.)_(.))Ż/.
    ŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻŻ
    Little did the bunnies suspect that one of them was a psychotic mass murderer with a 6 ft. axe.


  •  

    Posting Permissions

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