0

I'm trying to show a link to a German version of my landing page if German is one of the browser languages, but the issue I am having is that the array is returning all languages in one value. How can I check to see if the value contains certain letters? Here is the code I am using and the return I see:

$langarray = array(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,100));
if(in_array('de', $langarray)){
    $showdelink = '<a style="color: #004f5d;" href="/de/">View the DE homepage</a>';
}

I am getting the following returned:

Array ( [0] => en-US,en;q=0.9,de;q=0.8 )

So the issue I am having is the value is not specifically "de", but does contain "de", so the link is not displaying. How can I check that "de" is withing the returned value. Thank you

Robert
  • 143
  • 14

1 Answers1

1

you could use strpos, as

if(strpos($langarray[0], "de") !== false) {
    $showdelink = '<a style="color: #004f5d;" href="/de/">View the DE homepage</a>';
}
Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162
  • Thank you! That works perfectly, I will accept this as correct solution in 2 minutes when the question is old enough to accept an answer, I really appreciate it – Robert Jun 14 '21 at 00:34