Reputation: 13009
I have a PHP script that I am using to generate some rather complicated javascript for a web application. It is necessary that this script be generated by PHP for scalability reasons.
Here is my problem:
if I name the file myscript.js
, then I have to use htaccess to tell the webserver to pipe this through PHP (not preferrable)
if I name the file myscript.php
, then Zend Studio will highlight all the code as HTML instead of javascript.
What I am doing now is simply naming the script myscript.php
, and wrapping all the code in <script>
tags, then doing include('myscript.php')
instead of the preferred: <script src='myscript.php'>
.
I could thwart this whole problem if only I could tell Zend Studio to highlight this file as though it were a *.js
file. Is there a way of accomplishing this?
Currently I am using versions 5.5 (for Windows, at work) and 6.1 (for Linux, at home).
Upvotes: 2
Views: 1135
Reputation: 28124
I've found a very easy hack to cause zend to think of the PHP file as javascript:
// <script type="text/javascript">
alert("Hi");
// </script>
But I think Pascal's approach is cleaner...
Upvotes: 0
Reputation: 401002
Is there not a way to open your file with the Javascript editor ?
Something like right click on the file's name, then "Open With > Javascript editor" ?
Well, I've just tried with Zend Studio (I don't find the version number, but it's a pretty recent one, downloaded less than one month ago -- and Eclipse based)
To see "Javascript editor" in the "Open with" list, you might have to add a file association between .php and "Javascript". To do that, follow these steps :
Now, in the files list, you should be able to right click on a PHP file, and "open with > javascript editor"
And your file should be highlighted like a JS one, and not as PHP.
I'm not sure Zend studio will remember the fact that one file has to be opened with JS editor, though : you might always have to use "open with" for the file you are interested in.
Hope this helps ;-)
Upvotes: 3