开发者

How can I use PHP as a programming language?

I heard that PHP can be used without a web server, and it executes like C++ or Java. How can I do that? What p开发者_StackOverflowrogram do I use?


You should install PHP on your PC, than you may run php via

/path/to/php /path/to/script.php

on your console.

Besides, on *nix systems you may made it executable (chmod) and add

#!/path/to/php

to head of your script. It will allow you to run it by just calling script


That's PHP CLI. Command line usage.

Here's all you need http://php.net/manual/en/features.commandline.php

If you're on windows you run a file :

php.exe -f myfile.php


PHP can be used as a command line scripting language.


php comes with a php executable (on debian systems, you need to install the package php5-cli). Then, either write a file test.php and execute it on the command line with php test.php, or use the -r argument for short one-liners:

$ php -r 'echo date("%c") . "\n";'
%2011-10-12T00:29:39+02:00

If the executable is not in your PATH, you need to give the full path to php, like /usr/local/bin/php.


PHP can be executed via command line, but if you're thinking of a GUI or something, that's different. You'd basically be building a website. I don't think you'll be creating native Windows, Mac OSX, iPhone or Android apps any time soon with PHP.

If you want a way to compile PHP, check this out:

http://www.roadsend.com/home/index.php?pageID=compiler

Either way, if you want to run it like C++ or Java, you'll still need PHP on your system as an interpreter. I don't believe you can get around that.


Yes, you can use php in a stand-alone fashion. How you obtain a command-line version depends a bit on your platform, in fedora, you can su -c 'yum install php-cli', and then you will have a program called php to run your scripts.


Doing this entails, if you're on Linux, creating a bash-like script where you specify the PHP interpreter at the top of the file, like this:

#! /your/path/to/php -q

See: http://www.ibm.com/developerworks/opensource/library/os-php-command/

Or just

/your/path/to/php /my/php.file
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜