Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

132
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda