PHP Compiler

Code
Output

        

What Is the PHP Online Compiler?

This tool lets you run PHP scripts directly in your browser without installing PHP, a web server, or any local development environment. It is ideal for quickly testing code snippets, learning PHP syntax, and experimenting with built-in functions.

Your code is sent to a remote sandboxed server powered by the Piston execution engine, which runs the script in CLI mode and returns the output. The compiler supports standard input via the STDIN field and command-line arguments via the Args field, so you can simulate real-world script execution from the command line.

How It Works

  1. Write your PHP code in the editor panel. Your code must begin with the <?php opening tag, just as any PHP script requires. The editor starts with a simple "Hello, PHP!" example.
  2. Provide input in the STDIN field if your script reads from standard input using fgets(STDIN) or readline(). Each line in the STDIN box corresponds to one line of input. Leave this field empty if your program does not need any input.
  3. Add command-line arguments in the Args field if your script reads from $argv. Enter arguments separated by spaces.
  4. Click the Run button to send your code to the Piston execution server. The server runs PHP in CLI mode inside a sandboxed container and captures all output.
  5. View the results in the Output panel. You will see everything your script outputs via echo, print, var_dump(), or print_r(), along with any error messages or warnings.

Step-by-Step Example

Suppose you want to write a script that greets a user and performs basic string manipulation. Here is how you would do it using this compiler:

First, type the following code into the editor panel:

<?php
$name = trim(fgets(STDIN));
$upper = strtoupper($name);
$length = strlen($name);
echo "Hello, $upper! Your name has $length characters.\n";

Next, go to the STDIN field and type a name, for example Alice. This value will be read by the fgets(STDIN) call when the script runs.

Now click the Run button. The compiler sends your code and the STDIN data to the execution server. After a moment, the Output panel displays:

Hello, ALICE! Your name has 5 characters.

The script reads the name from standard input, converts it to uppercase with strtoupper(), calculates the length with strlen(), and prints the result. You can change the STDIN value and click Run again to test with different inputs without modifying the code itself.

Use Cases

Limitations and Notes

Frequently Asked Questions

What PHP version is used?

It runs the latest PHP 8.x version available through the Piston execution engine.

Do I need the opening PHP tag?

Yes, your code must start with the <?php opening tag for the interpreter to process it.

Can I use built-in functions?

Yes, PHP standard library functions such as array_map(), strlen(), preg_match(), and json_encode() are fully available.

Can I use Composer packages?

No, only PHP built-in functions and the standard library are available. Composer and third-party packages are not supported.

Is this a web server?

No, PHP runs in CLI mode here. There is no HTTP request handling, no $_GET or $_POST superglobals, and no HTML rendering.

Can I read input?

Yes, use fgets(STDIN) or readline() in your code and provide the input data in the STDIN field.

Does this support PHP frameworks?

No, frameworks like Laravel and Symfony require Composer. Use the Laravel API simulator for framework testing.

Is there a time limit?

Yes, code execution has a timeout to prevent infinite loops and long-running scripts.

Sources and References

Related Compilers