Select URL trimming - Multilingual parts?

Discussion in 'PHP' started by peppy, Aug 2, 2009.

  1. #1
    I have a multilingual page URLs like this:

    http://www.mysite.com/more/stuff/ (English)
    http://www.mysite.com/de/more/stuff/ (German)
    http://www.mysite.com/fr/more/stuff/ (French) ........

    I have a second multilingual site that I am trying to link to in every language to it's respective language on the second site. The problem is my language translator is software that automatically translates so I can\'t manually put the URL on these pages except the English version.

    How do I set up a PHP select URL trimming so it pulls out the "/de/" and "/fr/"
    and places it onto my link "http://www.mysecondsite.com"?

    I already tried doing this:
    <a href="http://www.mysecondsite.com/'; 
    
    $mystring = $_SERVER['REQUEST_URI'];
    
    $parts = explode("/",$mystring);
    //break the string up around the "/" character in $mystring
    
    $mystring = $parts['0'];
    //grab the first part
    
    echo $mystring;  
    
    echo'"><b>Link to my second site<b></a> 
    Code (markup):
    It works fine for all the translated languages except the English one because it results in this kind of URL: "http://www.mysecondsite.com/more/"

    Is there any way for this code to work where it doesn\'t grab anything ONLY in the English language?

    Please help
    Thanks
     
    peppy, Aug 2, 2009 IP
  2. keaglez

    keaglez Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    maybe perform some checking of the name that was grabbed?

    such as
    
    $mystring = (strlen($mystring) == 2) ? $mystring : "";
    
    PHP:
    since the string you grabbed usually is 2 characters, that should work in this case...

    or create an array of supported language and check the string against it...
     
    keaglez, Aug 3, 2009 IP