Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
One strings displays one thing but other it cotains the other string

I'm coding and I need to pass variables from javascript to PHP. I found the solution but it behaves a little different than expected

<script>
    var res = navigator.language;
</script>

<?php

$lang = "<script>document.writeln(res);</script>";

$string = file_get_contents("country.json");
if ($string === false) {
    // deal with error...
}

$json_a = json_decode($string, true);
if ($json_a === null) {
    // deal with error...
}
// echo $lang;
echo var_dump($lang); // On page it does display what I need and that is string(39) "sr-RS"
foreach ($json_a as $countryCodes) {
    // echo var_dump($countryCodes["twoLetter"]);
    if($lang == $countryCodes["twoLetter"]){
        echo "Success";
    }
}
?>

This is what I see on my page string(39) "sr-RS". In 39 characters it contains the <script>document.writeln(res);</script>. So I can not compare these two different values since they are different. Do you know how could I convert it or format it?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda