how to write php in script file

Solutions on MaxInterview for how to write php in script file by the best coders in the world

showing results for - "how to write php in script file"
Gael
18 Sep 2019
1<script type="text/javascript">
2var phpVars = { 
3<?php 
4  foreach ($phpToJsVars as $key => $value) {
5    echo '  ' . $key . ': ' . '"' . $value . '",' . "\n";  
6  }
7?>
8};
9</script>
10
Alayna
05 Feb 2019
1<script type="text/javascript" src="YourFunctions.js"></script>
2<script type="text/javascript">
3    functionOne(<?php echo implode(', ', $arrayWithVars); ?>);
4    functionTwo(<?php echo $moreVars; ?>, <?php echo $evenMoreVars; ?>);
5</script>
6
Lena
23 Jul 2020
1<?php
2$phpToJsVars = [
3  'value1' => 'foo1',
4  'value2' => 'foo2'    
5];
6?>
7
Lilly
30 May 2016
1AddType application/x-httpd-php .js
2
3AddHandler x-httpd-php5 .js
4
5<FilesMatch "\.(js|php)$">
6SetHandler application/x-httpd-php
7</FilesMatch>
8
María Camila
22 Sep 2017
1phpVars["value1"]
2phpVars["value2"]
3