PHP parse a specific .js file.
Moderator: General Moderators
PHP parse a specific .js file.
How can I get my server to have PHP parse a JavaScript file (e.g. foo.js) using an .htaccess file? For example. I have a file called "foo.js". I would like to tell my server, using an .htaccess file, that I want the php parser to parse this file. How would I do this? Sorry for keeping this message a little short but my enter key is not working on Firefox again. It's a bit annoying but I'm going to have to restart my browser.
Thanks for reading, and I appreciate any help with this.
Re: PHP parse a specific .js file.
Code: Select all
<Files foo.js>
ForceType application/x-httpd-php
</Files>
Re: PHP parse a specific .js file.
Yes this was one of the result I got from google. But doesn't this code just force foo.js to respond to the client with a different mime-type, other then application/x-javascript? When I put his in my .htaccess and open foo.js with firefox, firefox asks me to download this file rather then displaying the contents right on the viewport of the browser like it usually does with javascript files. So this suggest that it's just changing the content-type header of the file rather then having php parse the js file.Weirdan wrote:Code: Select all
<Files foo.js> ForceType application/x-httpd-php </Files>
EDIT: I'm pretty sure that's all it does; It just forces the files mime-type to be something else. I don't want the mime-type of the file to be anything other then application/x-javascript, application/javascript or text/javascript. What I'm trying to accomplish is a way to tell my server to parse this file with php's parser before it's sent to the clients browser.
I've found that this:
Code: Select all
<Files foo.js>
AddHandler x-httpd-php5 .js
</Files>
Code: Select all
<Directory /path/>
<Files foo.js>
AddHandler x-httpd-php5 .js
</Files>
</Directory>
-
timwhitlock
- Forum Newbie
- Posts: 1
- Joined: Thu Feb 12, 2009 3:36 pm
Re: PHP parse a specific .js file.
As nobody will see the URL to your .js file, why not just use a .php file? Perhaps identify it for your own benefit, like foo_js.php?
You'll still need to maintain the JavaScript mime type, but that's easy - just add the following to the top of the file:
If you're interested in parsing JavaScript with PHP, check out these two URLs:
http://jaspa.org.uk/
http://web.2point1.com/2008/05/09/full- ... r-for-php/
You'll still need to maintain the JavaScript mime type, but that's easy - just add the following to the top of the file:
Code: Select all
<?php
header('Content-Type: application/x-javascript', true);http://jaspa.org.uk/
http://web.2point1.com/2008/05/09/full- ... r-for-php/
Re: PHP parse a specific .js file.
Come on, this thread is 1 year old... stop necro-digging 