Question: I would like to make something like *tryruby.org*. I take a line from the user (e.g., `echo __FILE__`) and I want to execute it in PHP and return the output back to the client.

I tried to do `exec('php -r ' . $command, $output)`, but `$output` always contains the PHP help section.

How can I implement this feature?

Answer: 
To make `php -r` you have to have to put the code you want to execute between `'` .. your code .. `'`

Example:

```
php -r ' $var = 34; print_r($var); '

```
<http://tryruby.org> seems have an interactive Ruby shell. That seems to be a good starting point.

Here are two projects that provide such a shell for PHP: [php\_repl](https://github.com/ieure/php_repl) and [phpsh](http://www.phpsh.org/).

The other part is the web interface for the interactive shell. For that part, I suggest you have a look at [repl.it](http://repl.it/), which provides this service for many languages (but sadly not PHP). [Here's a link](https://github.com/replit/repl.it) to it's source code.

With this combination, you should be able to complete cour project.