Executing PHP in command line
Submitted by amitsedai on Mon, 01/14/2013 - 14:49There are times when one needs to execute PHP in command like, for example trying the date command output or a one line execution. For trivial tasks, executing the same at the command line without the need for writing and executing at a file level is a great tool for time saving.
The argument to be used is : -r
Example:
php -r '
$a = range(0,2);
foreach($a as $b) {
echo "entry: $b\n";
}
'
The output is:
entry: 0
entry: 1
entry: 2
Another example:
php -r '
> echo date("d-m-Y");
> echo "\n";
> '
14-01-2013