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 8 of 8
  1. #1
    New Coder
    Join Date
    Dec 2003
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts

    variable within variable

    Hi,
    Im trying to make my little script avaliable in different languages but i can not figureout how to do this:

    lets say i have this language variable in different files:

    english.php
    PHP Code:
    $l_welcome "$user welcome to our site."
    french.php
    PHP Code:
    $l_welcome "$user bienvenue à notre emplacement."
    whenever i print $l_welcome from some other file and i define $user before i print it i get no value for $user. Anyone know any other way to do this or tell me what i'm doing wrong?

    NOTE: I don't speak French, i used altavista.

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this becuase a variable is not assigned when the variable is printed, but when the script is loaded... you will need $user set BEFORE you include the languages file.

  • #3
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your code should work. Maybe $user is Empty ?

    try
    PHP Code:
    $l_welcome $user 'welcome to our site.'
    or if you have a lott off languages

    PHP Code:
    $l_welcome $user
    switch ($language){
       case 
    'eng':
           
    $l_welcome = . ' welcome to our site.';
           break;
       case 
    'fr':
           
    $l_welcome = .  bienvenue à notre emplacement.";  
           break;
    ...

    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #4
    New Coder
    Join Date
    Dec 2003
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by missing-score
    this becuase a variable is not assigned when the variable is printed, but when the script is loaded... you will need $user set BEFORE you include the languages file.
    That's what i thought and i did that but still its the same thing....

    Quote Originally Posted by raf
    Your code should work. Maybe $user is Empty ?
    no its not empty, i printed the variable to see if its empty but it wasn't

    here is the code that i use:
    PHP Code:
    /*/////// 

    format of $row['printmesazhi']

    [category]:[category2]:[otherstuff]:[otherstuff]

    */
    /
    while ( 
    $row =$log_list->putin_array()) {
        list(
    $fld1,$fld2,$fld3$fld4) = explode(":"$row['printmesazhi']);
        include_once(
    DIRNOW."lang/".$lang.".php");
        echo 
    $l_admin_del_msg;
        if (
    $fld1 == "del"){
            
    $row['url'] = "#";
            
    $row['printmesazhi'] = $l_admin_del_msg;
        }elseif(
    $fld1 =="edi"){
            
    $row['url'] = "v.php?id=$fld4";
            (
    $fld3 == "Yes")?$aprv $l_yes:$aprv=$aprv;
            (
    $fld3 == "Po")?$aprv $l_yes:$aprv=$aprv;
            (
    $fld3 == "No")?$aprv $l_no:$aprv=$aprv;
            (
    $fld3 == "Jo")?$aprv $l_no:$aprv=$aprv;
            
    $row['printmesazhi'] = $l_admin_edit_msg;
        }elseif(
    $fld1 =="add"){
            
    $row['url'] = "v.php?id=$fld4";
            
    $row['printmesazhi'] = $l_usr_add_wrd;
        }
        
    array_push$log $row );


    // HERE IS A LANGUAGE SAMPLE
    $l_admin_del_msg "Admin deleted $fld2 from the database";


    ps. the variable isn't always in the front it may be in the sentence.
    Last edited by fimi; 04-25-2004 at 01:48 AM.

  • #5
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Your code should work. Maybe $user is Empty ? no its not empty, i printed the variable to see if its empty but it wasn't
    Euh. So you printed it and it shows a value, but by the time you print it somewhere else in your code, it doesn't print anything at all. What would that mean?

    ICan you show me what that piece of code has to do with your initial post/problem?
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #6
    New Coder
    Join Date
    Dec 2003
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by raf
    Euh. So you printed it and it shows a value, but by the time you print it somewhere else in your code, it doesn't print anything at all. What would that mean?

    ICan you show me what that piece of code has to do with your initial post/problem?
    I posted the code that i'm having problems with! see my post above.

  • #7
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Maybe someone smarter understands what the posted code has to do with your problem. Naimly that the $user inside

    $l_welcome = "$user welcome to our site.";

    doesn't print anything while it is not empty. Because your posts makes no sense at all to me.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #8
    New Coder
    Join Date
    Dec 2003
    Posts
    80
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by raf
    Maybe someone smarter understands what the posted code has to do with your problem. Naimly that the $user inside

    $l_welcome = "$user welcome to our site.";

    doesn't print anything while it is not empty. Because your posts makes no sense at all to me.
    What are you talking about? the code that i posted is the problem...

    PHP Code:
    // here i assign the values for fld1, fld2 and so on
    list($fld1,$fld2,$fld3$fld4) = explode(":"$row['printmesazhi']); 
    /*
    $row['printmesazhi'] has this format
    [category]:[category2]:[otherstuff]:[otherstuff2] 


    */ 
    PHP Code:
    // here i include the language file after i assign the values to variables fld1 fld2 and so on.
    include_once(DIRNOW."lang/".$lang.".php"); 

    //Now i try to print it but i get no value for $fld#
    echo $l_admin_del_msg

    // the variable that i'm printing has this value:
    $l_admin_del_msg "Admin deleted $fld2 from the database"
    i don't know how else to ask!


  •  

    Posting Permissions

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