...

View Full Version : variable within variable



fimi
04-25-2004, 12:07 AM
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

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

french.php

$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.

missing-score
04-25-2004, 01:05 AM
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.

raf
04-25-2004, 01:07 AM
Your code should work. Maybe $user is Empty ?

try


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


or if you have a lott off languages



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

fimi
04-25-2004, 01:40 AM
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....


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:


/*///////

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.

raf
04-25-2004, 10:12 AM
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?

fimi
04-25-2004, 02:22 PM
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.

raf
04-25-2004, 02:37 PM
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.

fimi
04-25-2004, 05:02 PM
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...



// 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]


*/



// 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!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum