tags:

views:

666

answers:

12

I'm not much of a programmer, PHP is where I'm comfortable. And sometimes I find that I need to do things, such as arrange files or rename files on a mass scale on my computer. And I think I could do this with PHP but I can't of course.

So I was curious, is there a way I could run PHP files as kind of exe files.

I'll probably get flamed for this question, but yeah...

EDIT: Fairly important point, using Windows.

+1  A: 

Sure, just add #!/path/to/php to the top of the file, add the code in tags, and run it as a shell script.

Works fine - the php binary you use is either the cgi one or the purpose built CLI version.

http://www.php-cli.com/

http://php.net/manual/en/features.commandline.php

Moo
this only works on unix
Toad
Works in windows as well , the path would just be different
RC1140
How would a shell script work on windows? Some how I doubt the instructions here work for that.
Tchalvak
+5  A: 

just use php.exe (put it in your path) and the name of the php file you want to execute

Toad
e.g. Put it in c:\windows\system32
GaZ
gaz: The proper way is to use the PATH environment variable (config->system->env variables). But your method (although crude) might work also
Toad
A: 

it would appear so, yes.

Simon
That's not exactly what he is asking about.
FractalizeR
+4  A: 

You should have a look at php gtk

mnml
This is also not what he is asking about
FractalizeR
He might want to make a GUI for his "desktop application".
mnml
php gtk... what .... eeee... ok... well why not ;)
Johan
In that vein, there's also WinBinder: http://winbinder.org
Narcissus
+3  A: 

It's not as bad as you put it. PHP may be a very good tool for string related stuff like parsing, renaming etc. Especially if you know PHP.

To use php as script you should add #!/path/to/php as first line and set execution permissions on unixoid systems. In windows you can simply assign the php file ending with your php cli exe so you can click on them or use the script with the "start" command in the windows shell. But make sure that you write your scripts in a way that it is sensible to the current working directory. It may be different to what you might expect sometimes.

Patrick Cornelissen
A: 

maybe php is not the right tool to doing this and it's about time to learn another language...use this chance to expand your programming horizion

Jochen Hilgers
php works just fine for these things. Would safe him a lot of time learning something different. Expanding one's programming horizon is never a bad idea, just do it for the good reasons ;^)
Toad
doing file operation in a desktop environment with a script language (which focus on websites/server use) is a good reason for me ;)
Jochen Hilgers
@Jochen Hilgers So I should scrap all of my PHP desktop scripts (some of which I've been using for years, and some of which do complex file operations, both local and network)?
GZipp
no one said that... Ben Shelock has no existing scripts and so i see it as a good opportunity to learn something new ( if there is enough time and passion)
Jochen Hilgers
That's fair enough.
GZipp
I think the "simplicity" rule overshadows the "learn a new language for it" idea.
Tchalvak
+2  A: 

to be able to execute php files with double click, just like normal programs, go to the command line, then type

ftype php_script "C:\path\to\php.exe" "%1"
assoc .php=php_script
stereofrog
A: 

See the .reg file in this gist, it makes it possible to use .php files exactly like .bat files, e.g. my_script.php foo bar baz

Don't forget to edit paths to suit your setup.

Leonid Shevtsov
A: 

http://www.appcelerator.com/products/download/ Still use html & css as a desktop app and now has support for php.

Gorilla3D
A: 

PHP based web apps like Wordpress and Mediawiki I think uses php to setup and configure itself. Just give IIS proper read/write rights and you can make a simple web app that does massive renaming, etc.. PHP doesn't have to always be used for writing out html.

eed3si9n
+1  A: 

Download Wamp Server, install it. Once thats done, add the path to the php.exe to your PATH settings. You can do this by going to control panel->system->change settings->advanced->environment variables. Edit the PATH, add a ';' to the end of the line and then past the path to the php.exe. This is on Vista, it might be different on XP or Windows 7.

My path looks like this after: C:\Sun\SDK\jdk\bin;C:\wamp\bin\php\php5.3.0

Once thats done, you'll be able to execute a php file from the command line. You could create shortcuts too.

C:\Users\Garth Michel>php test.php

This is a test

C:\Users\Garth Michel>

I used php for years as a scripting language before I even bothered to use it as a web programming language.

SynackSA
+1  A: 

Check out WinBinder

Dinah