Page 1 of 1

Syntax help

Posted: Thu Jun 17, 2010 11:47 am
by markosjal
I currently have calls to a translation table that look like this

Code: Select all

<?php echo $lang['ACCOUNT_LINK']; ?>
They are working just fine

I have added a number of items to the translation tables. Those additions are items that are already variables that the system currently calls like this

Code: Select all

<?php echo $rowsubcat['subcatname']; ?

Now I do not know the proper syntax to make this work but If I could say I need something like

Code: Select all

<?php echo $lang($rowsubcat['subcatname']); ?>
I want the result of $rowsubcat['subcatname'] to go through the translation table ($lang)


I see however that this may not be correct, but not sure I have not made an error elsewhere. If anyone underrstands what I am trying to do please let me know what is the correct syntax, if this is incorrct.

Any help appreciated.


Thanks

Mark

Re: Syntax help

Posted: Thu Jun 17, 2010 12:03 pm
by Weirdan

Code: Select all

<?php echo $lang[$rowsubcat['subcatname']]; ?>

Re: Syntax help

Posted: Thu Jun 17, 2010 3:02 pm
by markosjal
Yes that worked very well, biut only in the first part I tested. I have a hard time when it comes to the bracketing in PHP!
Some things I will never understand.

I have encontered two parts of the script where I thought I could use the same technique however it does not work

current code

Code: Select all

<a href="{$catlink}">$xcatname</a>

// I tried 
<a href="{$catlink}">$lang['$xcatname']</a>

and this does not work

In another place the current code is

Code: Select all

<?php echo "$row[catname] $path_sep $row[subcatname]"; ?>

and I tried 

<?php echo "$lang[$row['catname']] $path_sep $lang[$row['subcatname]]"; ?>
and this does not work either.

I tried double quotes, single quotes and no quotes.

Open to suggestions



Thanks

Re: Syntax help

Posted: Fri Jun 18, 2010 2:35 am
by Weirdan

Code: Select all

$lang['$xcatname']
doesn't work because you used single quotes. Variables in single quotes are not interpreted. You need to use $lang[$xcatname] here

Code: Select all

<?php echo "$lang[$row['catname']] $path_sep $lang[$row['subcatname]]"; ?>
Here you could either concatenate your variables into string (instead of interpolating) :

Code: Select all

<?php echo $lang[$row['catname']] . " " . $path_sep . " " . $lang[$row['subcatname']]; ?>
or use curly brackets for interpolation (so-called 'complex' syntax):

Code: Select all

<?php echo "{$lang[$row['catname']]} {$path_sep} {$lang[$row['subcatname']]}"; ?>