Online PHP Compiler

main.php
<?php
// Online PHP compiler (PHP 8.4)
// Write your code here and press Run.

echo "Hello, World!\n";

foreach ([1, 2, 3] as $i) {
    echo "The square of $i is " . ($i * $i) . "\n";
}

// Tip: to give your program keyboard input,
// type the values in the Input box below the output, one per line.
Output

Output will appear here. Press Run or Ctrl + Enter.

Ready

About this PHP compiler

This free online PHP compiler lets you write, run and test PHP 8 scripts without installing a web server. Type your code, press Run, and the output appears next to the editor.

PHP runs inside your browser using a WebAssembly build of the interpreter, so there is no account to create and your script is not sent to a server to be executed. It is a quick way to try a function, practise for a class, or check how an array or string function behaves.

How to use it

  1. Write or paste your PHP code in the editor. Start it with the <?php tag, as in any PHP file.
  2. If your script reads input with fgets(STDIN), type the values in the Input box below the output, one per line, in the order the script asks for them.
  3. Press Run (or Ctrl + Enter). The first run loads PHP (about 3 MB, kept by your browser afterwards), so later runs are faster.
  4. Read the output on the right. Warnings, notices and fatal errors are shown with the file and line number.

Features

  • PHP 8.4 with the standard library: arrays, strings, math, JSON, dates, classes and more
  • Reads keyboard input through the Input box with fgets(STDIN)
  • Warnings, notices and fatal errors with line numbers
  • A fresh PHP instance on every run, so nothing carries over by accident
  • No login, no install, works on any modern device
  • Dark and light themes, automatic saving, download as .php

Good to know

Frequently asked questions

Which version of PHP is used?

PHP 8.4, compiled to WebAssembly so it runs inside your browser.

How do I give my PHP script input?

Type the values into the Input box below the output, one per line, then press Run. Read them with fgets(STDIN) or file_get_contents("php://stdin").

Why is my code printed as plain text?

PHP only runs code inside the <?php ... ?> tags. Make sure your file starts with <?php.

Can I use a database or make web requests?

No. The script runs in a sandbox inside your browser with no network access or database server. It is meant for learning and testing PHP code itself.

Is it free?

Yes. There is no sign-up, and nothing is executed on our servers.

Other online compilers