Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

PHP - Using js into PHP code

0 votes
39 views
added Dec 17, 2020 in PHP by lcjr Second Warrant Officer (3,820 points)
<?php
   $myScript = file_get_contents('your-script.js');
   echo "<script>".$myScript."</script>";
?>

 

1 Response

0 votes
responded Dec 17, 2020 by lcjr Second Warrant Officer (3,820 points)
<?php
 // Break the echo into few parts to avoid conflicts when using single or double quote in JS
  echo '<script type="text/javascript">';
  echo 'document.write("Hey world!")';
  echo '</script>';

?>

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...