Table of Contents

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>

running without a file

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";'

interactive mode

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)