docs:programming:php:command_line

command line php

See the current options with php –help. If you want to run a file from the command line instead of through the browser, simply do this:

php <filename>

The -r flag tells php to not require code tags, and allows code to be used instead of a file name.

php -r 'echo date("Y-m-d h:i:s", strtotime("2004-10-28T16:37:15Z")) . "\n";'

PHP allows you to have commands executed as you type them. To start in interactive mode, use the -a switch.

$ php -a
Interactive mode enabled
 
<?
ob_start();
$now = time();
echo date("Y-m-d", $now);
exit("\n");

(output will be the current date)

  • docs/programming/php/command_line.txt
  • Last modified: 2009/01/10 23:27
  • by billh