Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!