run php in javascript file code example

Example 1: 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>

Example 2: how to run php inside js

You can't run PHP with javascript. JavaScript is a client 
side technology (runs in the users browser) and PHP is a 
server side technology (run on the server). If you want to 
do this you have to make an ajax request to a PHP script and 
have that return the results you are looking for.

Tags:

Php Example