Executing PHP from the command line in Linux

Because I always seem to forget the syntax, here's an example:

php -r 'if(true) echo "hi\n";'

Note that escaped characters need to be wrapped in double quotes. To run the code inside a file, use the syntax

php -f my_script.php $arg1 $arg2 $arg3

The arguments $arg1, $arg2, etc. can then be accessed within the script like so:

<?php

    $argument1 = $argv[1];
    $argument2 = $argv[2];
    $argument3 = $argv[3];
    
    // Do stuff...

?>

($argv[0] is the name of the script itself.)