PHP - Using js into PHP code

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

 

1 Response

0 votes
responded Dec 17, 2020 by lcjr First Warrant Officer (11,830 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.
...