views:

352

answers:

1

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:

  1. if I name the file myscript.js, then I have to use htaccess to tell the webserver to pipe this through PHP (not preferrable)

  2. 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).

+1  A: 

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 :

  • Windows > preferences
  • general > editors > file associations
  • add *.php to the list ("add" button) if it's not already in it (it is not by default, it seems)
  • when you click on *.php, you see two entries in the list at the bottom :
    • php editor
    • text editor
  • add "javascript editor" to this list (the other "add" button, next to the list) -- don't set it as default (as you only want a couple of .php files opened with it, not all of them)
  • click OK to validate

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 ;-)

Pascal MARTIN
hmm.. tough to get the best of both worlds. thanks!
Stephen J. Fuhry
you're welcome :-)
Pascal MARTIN