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 7 of 7
  1. #1
    Regular Coder
    Join Date
    Apr 2007
    Posts
    141
    Thanks
    3
    Thanked 1 Time in 1 Post

    still havent resolved language problem

    PHP Code:
    <?php 

    $default_lang
    'fr'

    if (isset(
    $_GET['lang'])) { $language $_GET['lang']; } else { $language $default_lang; }    


    $text[1]['en'] = "Last version";
    $text[1]['fr'] = "Derni&egrave;re";


    echo 
    $text[1][$language];



    function 
    set_link $base_url$language$text ) {
        return 
    '<a href=\"".$baseurl."?lang=".$language."\"">".$text."</a>';
        }
        
    $current_url$_SERVER['PHP_SELF'];    
    set_link$current_url"fr""French");
    set_link$current_url"en""English");
    ?>
    Instead of using session or cookies, I am trying to embed ?lang=$language into links . which these links set as trigger for 2 different language

    but it i think my function set_link does not work properly.

    either the return part was not right . or.. i am confused.

    help me ?
    thanks

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    PHP Code:
    function set_link $base_url$language$text ) {
        return 
    '<a href=\"".$baseurl."?lang=".$language."\"">".$text."</a>';
        }
    ?> 
    typo in function set_link, href must be $base_url not $baseurl

    regards

  • #3
    Regular Coder
    Join Date
    Apr 2007
    Posts
    141
    Thanks
    3
    Thanked 1 Time in 1 Post
    i think i should use echo instead of return .
    but apparently i still have problem with escaping the " to what i want . as normal <a href >


    any help is appreciated.

    thanks

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by likon View Post
    i think i should use echo instead of return .
    but apparently i still have problem with escaping the " to what i want . as normal <a href >
    any help is appreciated.

    thanks
    sorry, is my fault, I didn't look closer to quotes,

    PHP Code:
    function set_link($base_url$language$text){
      return 
    '<a href="'.$baseurl.'"?lang='.$language.'">'.$text.'</a>';

    return is ok, in my opinion but this way:
    PHP Code:
    $current_url$_SERVER['PHP_SELF'];    
    echo 
    set_link$current_url"fr""French");
    echo 
    set_link$current_url"en""English"); 
    regards

  • #5
    Regular Coder
    Join Date
    Apr 2007
    Posts
    141
    Thanks
    3
    Thanked 1 Time in 1 Post
    PHP Code:
    <?php 

    $default_lang
    'fr'

    if (isset(
    $_GET['lang'])) { $language $_GET['lang']; } else { $language $default_lang; }    


    $text[1]['en'] = "Last version";
    $text[1]['fr'] = "Derni&egrave;re";


    echo 
    $text[1][$language];



    function 
    set_link($base_url$language$text){
      return 
    '<a href="'.$base_url.'"?lang='.$language.'">'.$text.'</a>';
    }  
        
    $current_url$_SERVER['PHP_SELF'];
    $text"test link name";
    echo 
    set_link$current_url"fr""French");
    echo 
    set_link$current_url"en""English");
    ?>
    should the code become like this ?
    the <a href somehow does not show ?lang ?
    the escape seems right though ?

  • #6
    Regular Coder
    Join Date
    Apr 2007
    Posts
    141
    Thanks
    3
    Thanked 1 Time in 1 Post
    never mind . just remove the " in between base_url and ? lang.

    thanks a lot oesxyl

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by likon View Post
    never mind . just remove the " in between base_url and ? lang.

    thanks a lot oesxyl
    sorry is my fault I didn't see it,

    regards


  •  

    Posting Permissions

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