Can someone help with this easy php code?

Discussion in 'PHP' started by diego018, Jun 3, 2011.

  1. #1
    i have a wordpress blog in 2 languages. by default, i have:
    <meta http-equiv="Content-Language" content="ES">

    but i would like to have in some pages that are in English "EN" this meta tag changed.

    all posts that are in english are in a subfolder "url/en/post.html"

    how can i make with php that if the url has "url/en" it sends the word "EN" ?
     
    diego018, Jun 3, 2011 IP
  2. ntomsheck

    ntomsheck Peon

    Messages:
    87
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I have no idea how your server is set up, so this will most likely be inefficient code (is there actually a folder called 'en' or is that a mod_rewrite url?).

    $lang = "es" //set a default here, in case the script fails for whatever reason.
    if(preg_match("/\/en\//",$_SERVER['REQUEST_URI'])) { // will only match 'en' if it is preceeded and followed by one forward slash
    $lang = "en";
    } elseif(preg_match("/\/es\//",$_SERVER['REQUEST_URI'])) {
    $lang = "es";
    }
    ?>

    <meta http-equiv="Content-Language" content="<?php echo $lang ?>">
     
    ntomsheck, Jun 3, 2011 IP
    diego018 likes this.
  3. diego018

    diego018 Well-Known Member

    Messages:
    920
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    150
    #3
    thanks ! i will try it :D
     
    diego018, Jun 7, 2011 IP
  4. diego018

    diego018 Well-Known Member

    Messages:
    920
    Likes Received:
    46
    Best Answers:
    0
    Trophy Points:
    150
    #4
    thanks !! i made some modifications and it works !
    here is the one i used:
    <?php
    {$lang = "es, us";} //set a default here, in case the script fails for whatever reason.
    if(preg_match("/\/en\//",$_SERVER['REQUEST_URI'])) {
    $lang = "en, us"; //if the post has in the url /en/ show this.
    }
    ?>
    <meta http-equiv="Content-Language" content="<?php echo $lang ?>">

    this could be useful for blogs and sites in multiple languages. thanks for your help ntomsheck.
     
    diego018, Jun 7, 2011 IP