views:

1943

answers:

3

Is there any trick to run .PHP files in windows XP from any folder by double clicking like HTML file ?

I use XAMPP but in this we need to put files ina special htdocs folder. I want to run file from any folder, desktop by double clicking.

A: 

PHP comes with a command line interface interpreter called php.exe (in Windows). This can be found in the root of your PHP installation directory.

You will need to associate .php files with this interpreter. That is, go into Tools -> Folder Options -> File types, and register php.exe -f "%1" as the application for the .php file type.

That said, it's not very typical to want to 'run' a PHP file by double-clicking it - not many people would use PHP the same way they'd use, for example, batch files or shell scripts - PHP is much better suited to generating web pages, ie using it in a web server. Chances are, running PHP outside of a web server is not what you really want to do here. For example, the PHP file will run within a command window and its output will be plain text, and if you want to see its output your script will need to pause or wait for input from standard input itself after terminating.

More information at Using PHP from the command line

thomasrutter
I associated but it not works
metal-gear-solid
Sorry, just realise you need the -f bit. But again, this is probably not what you want to do - you probably want to keep running PHP with a web server and browser, not directly.
thomasrutter
+1  A: 

There is a significant difference in viewing HTML files vs. PHP files:

HTML files are static files interpreted by the browser. When you open them, the PATH to the HTML file is passes as an argument to the default browser which interprets and displays the file.

PHP files on the other hand are required to be interpreted by a PHP interpreter (XAMPP, in your case) before the resulting HTML is rendered by a browser. In this case, the local file PATH would have to be translated to the corresponding local URL, then sent to the browser.

Sample Solution
You could write a simple script that replaces '/var/www/' with 'http://localhost:8888/' (with a regular expression, for example) and passes that to the browser. Then, associate PHP files with your script.

Andy
can u tell me the process of making that script
metal-gear-solid
If you want to be able to place PHP files *anywhere* on your machine, though, that either: 1. will not work, or 2. will not be safe.
Andy
A simple BASH script can do find and replace. See this page: http://tldp.org/LDP/abs/html/string-manipulation.html
Andy
+3  A: 
metal-gear-solid