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

251
Views
¿Cómo puedo convertir la cadena de PHP en un número entero, pero la cadena de php se obtiene de javascript escrito en la misma página?
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>if else in php</title> </head> <body> <script> var a = 123; //to send the prompt value to php, reference taken from stack overflow </script> <?php $a = "<script>document.writeln(a)</script>"; echo $a; ?> </body> </html>

en el código anterior, obtuve el valor de la variable javascript 'a' en PHP, lo obtuve con éxito en la variable $a e intenté imprimirlo y luego también se imprimió correctamente. Como $a contendría el número '123' en la cadena, traté de convertirlo en un número entero usando la función intval() pero siempre me muestra el valor de $a como 0 cuando lo hago eco. el siguiente código describe lo mismo

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>if else in php</title> </head> <body> <script> var a = 123; //to send the prompt value to php, reference taken from stack overflow </script> <?php $a = "<script>document.writeln(a)</script>"; $a = intval($a); echo $a; ?> </body> </html>
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Tienes que enviarlo al servidor para procesarlo. Aquí un ejemplo de trabajo.

 <?php $canDrive = false; // use GET to retrieve the value of the "age" query string if(isset($_GET["age"]) && $_GET["age"] >= 18) $canDrive = true; ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>if else in php</title> </head> <body> <!-- Here goes your code --> <?php if ($canDrive) { echo "You can drive"; } else { echo "You can't drive"; } ?> <form action="" method="get"> <input type="text" name="age" id=""> <input type="submit" value="submit"> </form> </body> </html>

Recuerde, JavaScript y PHP no pueden comunicarse directamente.

about 4 years ago · Santiago Trujillo Report
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!