PHP problem to translate text

Discussion in 'PHP' started by eureka321, Jan 10, 2012.

  1. #1
    Hello,

    I am new to PHP and I was wondering if somebody could help me.
    I am using PHP to echo a bit of pre-translated text. You click here and your text is now in French.
    You get the idea.

    My problem is that with my script all the text echoed becomes a link, which I don't want.
    What am I doing wrong? Thanks some advise. :)

    <html>
       <head>
       </head>
       <body>
          <a href="./test.php?language=english">english</a>
          <a href="./test.php?language=french">french</a>
       <?php
       
    $language = english;
    
    if ( $_GET['language'] == english ) {
       echo "this text is in english";
    } else {
       echo "ce texte est en francais";
    }
       ?>
       </body>
    </html>
    HTML:
     
    eureka321, Jan 10, 2012 IP
  2. modz

    modz Well-Known Member

    Messages:
    95
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #2
    The error probably comes from the browser you are using, but don't make such mistakes: $language = english. The correct is $language = 'english'.
     
    modz, Jan 10, 2012 IP
  3. HuggyEssex

    HuggyEssex Member

    Messages:
    297
    Likes Received:
    4
    Best Answers:
    2
    Trophy Points:
    45
    #3
    Something like this would work fine

    
    <html>
    	<head>
    	</head>
    	<body>
    	<a href="./test.php?language=english">english</a> - 
        <a href="./test.php?language=french">french</a>
    <?php
    (isset($_GET['language']))?$lang='english':$lang='french';
    if($lang=='english') {
       echo 'this text is in english';
    } else {
       echo 'ce texte est en francais';
    }
    ?>
    	</body>
    </html>
    
    PHP:
     
    HuggyEssex, Jan 10, 2012 IP