How to use the online PHP compiler
- Write or paste a PHP script into the editor. The opening
<?phptag is optional; if your code contains no PHP tag at all, it is added for you. Templates that mix HTML and<?php ... ?>blocks work too. Reset example restores the starter code. - Press Run or use Ctrl + Enter (⌘ + Enter on a Mac).
- Everything your script outputs with
echo,print,printforvar_dumpappears in the Output panel. Warnings and fatal errors are highlighted. - Choose a time limit of 5, 15 or 60 seconds. Scripts that run longer are stopped automatically, and Stop ends a run at once.
The first run downloads the PHP interpreter, about 12 MB. Your browser caches it, so later runs start much faster. Use Copy or main.php to keep your script.
PHP runs locally inside your browser, so your code is never sent to or stored on our servers. The editor remembers your last script in your browser's local storage, and in no other place.
What's supported
The compiler uses PHP 8 through php-wasm, the PHP interpreter compiled to WebAssembly. It is not a simulation; your code is executed by PHP itself.
- PHP 8 syntax: typed properties, union types,
matchexpressions, named arguments, arrow functions (fn), the nullsafe operator (?->) and enums where the bundled version supports them. - Core functions for strings (
str_contains,sprintf,explode), arrays (array_map,usort,array_filter), maths and dates. - JSON with
json_encodeandjson_decode. - Regular expressions with the
preg_*functions. - Classes, interfaces, traits, closures, generators and exceptions.
Limitations:
- No network extensions:
curl, sockets and HTTP requests are not available. - No database server: there is no MySQL or PostgreSQL to connect to. To practise SQL, use the online SQL compiler.
- No web server context:
$_GET,$_POST, sessions and cookies do not get real request data, and HTML output is shown as text, not rendered. - No Composer packages, and no standard input.
PHP quick reference
<?php
$prices = ['apple' => 1.20, 'bread' => 2.50, 'milk' => 0.99];
$expensive = array_filter($prices, fn($p) => $p > 1);
arsort($expensive);
foreach ($expensive as $item => $price) {
printf("%-6s %5.2f\n", $item, $price);
}
$label = match (true) {
count($prices) > 2 => 'big basket',
default => 'small basket',
};
echo $label, PHP_EOL;
echo json_encode($prices, JSON_PRETTY_PRINT), "\n";
| Task | Syntax |
|---|---|
| Variable | $name = "Ada"; |
| String interpolation | "Hello, {$name}!" |
| Associative array | $a = ['key' => 'value']; |
| Loop over keys and values | foreach ($a as $k => $v) { } |
| Inspect a value | var_dump($x); or print_r($x); |
| Null coalescing | $v = $a['x'] ?? 'default'; |
Tips
- End lines with
"\n"orPHP_EOL;echodoes not add a newline on its own. - Use
print_r($array)for a compact view of nested arrays, orvar_dump()when you also need types and lengths. - For readable JSON, pass
JSON_PRETTY_PRINT, or paste the output into the JSON formatter to validate it. - Every run starts a fresh interpreter, so variables and functions from the previous run are not kept.
preg_match pattern? Build and debug it in the regex tester first, then paste it between the delimiters, for example '/^\d+$/'.Frequently asked questions
Do I need to start my code with <?php?
No. If the script contains no <?php tag, one is added automatically. You can also write HTML with embedded <?php ... ?> blocks, exactly as in a .php file on a web server.
Can I connect to MySQL?
No. The interpreter runs in your browser without network access or a database server. For SQL practice, the SQL compiler gives you a real SQLite database in the browser.
Why don't curl or file_get_contents() with a URL work?
Network extensions are not included in this WebAssembly build, and browsers do not allow raw network connections from a sandbox like this one.
Is this the same as running PHP on a server?
For language features, string, array and JSON functions, yes: it is the real PHP engine. Anything that depends on a web server, extensions or the network behaves differently.