Adding a variable in array

Discussion in 'PHP' started by web@master24, Jul 29, 2009.

  1. #1
    Hi, im have a lot of text in my website inside of arrays like:

    echo "[<a href=\"myplaylist\">Mi Lista de reproduccion</a>] &nbsp;&nbsp;";
    echo "[<a href=\"process.php\">Salir</a>]";

    and want change the words like:

    Mi lista de reproduccion and Salir for variables like:

    <?=$lang['salir'];?>

    Its possible do that? because i try to change but showme an error
     
    web@master24, Jul 29, 2009 IP
  2. tguillea

    tguillea Active Member

    Messages:
    229
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #2
    I'm guessing it is to make this website compatible with multiple language outputs depending on user preferences, but tell me if I'm wrong and my method doesn't work.

    The problem is, its easier than you are making it. Can you not simply replace the text in your PHP file so that instead of saying 'Mi Lista de reproduccion' it says "$lang['mi lista de reproduccion']", and you are getting an error because you do not need to include the <? and ?> because you have already told the script you are in "PHP mode" (evident because you are already using the PHP function echo in your script).

    so replace the anchor text "Salir" with "$lang['salir']" and then make sure your quotes are all in the right place
     
    tguillea, Jul 30, 2009 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    Indeed, in your example you must do this like this way

    echo "[<a href=\"myplaylist\">" . $lang['Mi Lista de reproduccion'] . "</a>] &nbsp;&nbsp;";
    echo "[<a href=\"process.php\">" . $lang['salir'] . " </a>]";

    Best way is to add all language variables to one PHP file so you can change this on the fly and even when you think you will add another language, you only have to recreate the language php file.

    Have fun!
     
    EricBruggema, Jul 30, 2009 IP
  4. web@master24

    web@master24 Active Member

    Messages:
    418
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    90
    #4
    Thanks to both, work great, thank you
     
    web@master24, Jul 30, 2009 IP