Question

I have the following code to set a variable, $lang, depending on what directory we are currently in:

$find_lang = $_SERVER['REQUEST_URI'];
if (strpos('$find_lang', '/fr/') !== false) {
    $lang = "fr";
}
else if (strpos('$find_lang', '/de/') !== false) {
    $lang = "de";
}
else {
    $lang = "en";
}
echo $lang;
parse_ini_file($lang . ".ini");

However, echoing $lang always gives me "en", even if I'm in http://example.com/fr/. I believe it's because of the forward slashes around the directory, but I've tried escaping as follows: //fr// and \/fr\/ but neither gives me a different answer.

Any ideas?

Was it helpful?

Solution

   $find_lang = $_SERVER['REQUEST_URI'];
   if (strpos($find_lang, '/fr/') !== false) {
     $lang = "fr";
   }
   else if (strpos($find_lang, '/de/') !== false) {
      $lang = "de";
   }
   else {
     $lang = "en";
   }
    echo $lang;
   parse_ini_file($lang . ".ini");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top