title: Execute a string of PHP code on the command line
body: <p>I'd like to be able to run a line of PHP code on the command line similar to how the following options work:</p>
  <pre><code>perl -e &quot;print 'hi';&quot;
  python -c &quot;print 'hi'&quot;
  ruby -e &quot;puts 'hi'&quot;
  </code></pre>
  <p>I'd like to be able to do:</p>
  <pre><code>php &quot;echo 'hi';&quot;
  </code></pre>
  <p>I've read that there is a <code>-r</code> option that can do what I need for php, however it doesn't appear to be available when I try to use it.  I've tried using PHP 5.2.13 and PHP 4.4.9 and neither have an <code>-r</code> option available.</p>
  <p>I wrote this script (that I called run_php.php) - which works, but I'm not a huge fan of it just because I feel like there should be a more &quot;correct&quot; way to do it.</p>
  <pre><code>#!/usr/bin/php5 -q
  &lt;?php echo eval($argv[1]); ?&gt;
  </code></pre>
  <p>Is there a <code>-r</code> option?  If so, why is it not available when I run <code>--help</code>?  If there is no <code>-r</code> option, what is the best way to do this (without writing an intermediary script if possible)?</p>
  <hr/>
  <p>Because I don't think it was very clear above, the <code>-r</code> option is <em>not</em> available to me.  Here is the <code>php -h</code> output for both versions of PHP that I'm running.</p>
  <p>PHP 4.4.9</p>
  <pre class="lang-none prettyprint-override"><code>Usage: php [-q] [-h] [-s] [-v] [-i] [-f &lt;file&gt;]
         php &lt;file&gt; [args...]
    -a               Run interactively
    -C               Do not chdir to the script's directory
    -c &lt;path&gt;|&lt;file&gt; Look for php.ini file in this directory
    -n               No php.ini file will be used
    -d foo[=bar]     Define INI entry foo with value 'bar'
    -e               Generate extended information for debugger/profiler
    -f &lt;file&gt;        Parse &lt;file&gt;.  Implies `-q'
    -h               This help
    -i               PHP information
    -l               Syntax check only (lint)
    -m               Show compiled in modules
    -q               Quiet-mode.  Suppress HTTP Header output.
    -s               Display colour syntax highlighted source.
    -v               Version number
    -w               Display source with stripped comments and whitespace.
    -z &lt;file&gt;        Load Zend extension &lt;file&gt;.
  </code></pre>
  <p>PHP 5.2.13</p>
  <pre class="lang-none prettyprint-override"><code>Usage: php [-q] [-h] [-s] [-v] [-i] [-f &lt;file&gt;]
         php &lt;file&gt; [args...]
    -a               Run interactively
    -C               Do not chdir to the script's directory
    -c &lt;path&gt;|&lt;file&gt; Look for php.ini file in this directory
    -n               No php.ini file will be used
    -d foo[=bar]     Define INI entry foo with value 'bar'
    -e               Generate extended information for debugger/profiler
    -f &lt;file&gt;        Parse &lt;file&gt;.  Implies `-q'
    -h               This help
    -i               PHP information
    -l               Syntax check only (lint)
    -m               Show compiled in modules
    -q               Quiet-mode.  Suppress HTTP Header output.
    -s               Display colour syntax highlighted source.
    -v               Version number
    -w               Display source with stripped comments and whitespace.
    -z &lt;file&gt;        Load Zend extension &lt;file&gt;.
  </code></pre>
  <p>There is <em>no</em> -r option. When I try to use the <code>-r</code> option I get:</p>
  <blockquote>
  <p>Error in argument 1, char 2: option not found r</p>
  </blockquote>
  <p>Sorry for the confusion.</p>