-r or --run : This runs a line of PHP code supplied as the argument, rather than executing it from a file. The line of code should be enclosed by single quotes because shells like bash will try to interpolate PHP variables as if they were shell variables if you use double quotes. This performs a similar role to the -a interactive mode, except that PHP’s “state” is cleared after each line is executed. This means that the line of code supplied is treated as the whole script to be executed, and execution is terminated once it has been run. Here’s an example that will print out "4" followed by a new line character:
~$ php -r "echo (2+2).\"\n\";"
Note that the line must be well-formed syntactically correct PHP,so don’t miss the semicolon at the end! I will return to -r later in this chapter in the section "The Many Ways to Call PHP Scripts."
~$ more my_text_file.txt | php -B "echo \"Lets add line numbers...\n\";" -R "echo \"$argi: $argn\n\";" -E "echo \"That's the end folks\n\";"
~$ more my_text_file.txt | php -B "echo \"Lets add line numbers...\n\";" -R 'echo "$argi: $argn\n";' -E "echo \"That's the end folks\n\";"