“Cómo incluir JavaScript en PHP” Código de respuesta

Cómo agregar JavaScript a un archivo PHP

//this is my code 

you can add javascript to your code by using the echo statement and rap all 
your javascript between "" and if there is "" in the javascript code
then add \ before any "", and for the php inside rap it with ''
  
  
<?php
  echo "<script>document.write(\"hello world\")</script>"
?>
  
//other example

<?php
  $a = 5;
  echo "<script>document.write('$a')</script>"
?>

//other example
  
<?php 
$TokenData = Auth::user();

echo "<script type=\"text/javascript\">
             localStorage.setItem(\"id\", '$TokenData->id');
             localStorage.setItem(\"name\", '$TokenData->name');
             localStorage.setItem(\"email\", '$TokenData->email');
      </script> ";
Wide-eyed Wryneck

Cómo incluir JavaScript en PHP

// simply echo the path anywehre in php you need

echo "<script src="script.js" type="text/javascript"></script>"
Himanshu Jangid

Use PHP en el archivo JavaScript

<script type="text/javascript">
	var myString = '<?php echo 1+1; ?>';
</script>
Undefined

Respuestas similares a “Cómo incluir JavaScript en PHP”

Preguntas similares a “Cómo incluir JavaScript en PHP”

Más respuestas relacionadas con “Cómo incluir JavaScript en PHP” en PHP

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código