Answers for "how to write php in js file"

0

write php in javascript

<script type="text/javascript">
	var myString = '<?php echo 1+1; ?>';
</script>
Posted by: Guest on August-02-2021
0

how to write javascript inside 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> ";
Posted by: Guest on November-03-2021
0

how to write php in script file

<script type="text/javascript" src="YourFunctions.js"></script>
<script type="text/javascript">
    functionOne(<?php echo implode(', ', $arrayWithVars); ?>);
    functionTwo(<?php echo $moreVars; ?>, <?php echo $evenMoreVars; ?>);
</script>
Posted by: Guest on October-17-2020
0

how to write php in script file

<?php
$phpToJsVars = [
  'value1' => 'foo1',
  'value2' => 'foo2'    
];
?>
Posted by: Guest on October-17-2020
0

how to write php in script file

AddType application/x-httpd-php .js

AddHandler x-httpd-php5 .js

<FilesMatch ".(js|php)$">
SetHandler application/x-httpd-php
</FilesMatch>
Posted by: Guest on October-17-2020

Browse Popular Code Answers by Language