Hello, World!
<?php
echo "Hello, World!\n";Tap Run to execute
main.php · output appears here
Press Run to execute
Output streams here as your program runs.
PHP is a dynamically typed, server-side scripting language created by Rasmus Lerdorf in 1994, originally as a set of tools for personal home pages. It was designed for embedding logic directly into HTML and generating dynamic web content. Over time it gained full object-oriented support, namespaces, closures, and a large standard library, evolving into a general-purpose language with a strong focus on the web.
Today PHP powers a large share of the web, including platforms like WordPress, Drupal, and frameworks such as Laravel and Symfony. Its dependency manager Composer and the Packagist registry support a vast package ecosystem. This compiler runs PHP 8.2.3, so you can use modern features like typed properties, enums, named arguments, the nullsafe operator, and just-in-time compilation.
main.php is the entry point. Add helper files from the explorer and import them into your project.
Use the Input panel to pipe standard input to your program when it needs data.
Run sends your code to a fresh hosted runtime and streams the result into the output panel.
Your draft stays in this browser, and Share creates a separate snapshot link.
main.php requires the sibling PHP file before calling its function.
<?php
require __DIR__ . '/helper.php';
echo answer(), "\n";
<?php
function answer(): int {
return 42;
}
<?php
echo "Hello, World!\n";<?php
$name = trim(fgets(STDIN));
echo "Hello, $name!\n";<?php
$fruits = ["apple", "banana", "cherry"];
foreach ($fruits as $i => $fruit) {
echo ($i + 1) . " " . $fruit . "\n";
}<?php
function factorial($n) {
return $n <= 1 ? 1 : $n * factorial($n - 1);
}
echo factorial(5) . "\n";<?php
function divide($a, $b) {
if ($b === 0) {
throw new InvalidArgumentException("Cannot divide by zero");
}
return $a / $b;
}
try {
echo divide(10, 0);
} catch (InvalidArgumentException $e) {
echo "Error: " . $e->getMessage() . "\n";
}<?php
$text = "banana";
$counts = [];
foreach (str_split($text) as $ch) {
$counts[$ch] = ($counts[$ch] ?? 0) + 1;
}
print_r($counts);<?php
$s = " Hello, World ";
echo strtoupper(trim($s)) . "\n";
$nums = [3, 1, 2];
sort($nums);
echo implode(", ", $nums) . "\n";<?php
class Person {
public function __construct(
public string $name,
public int $age
) {}
public function describe(): string {
return "$this->name ($this->age)";
}
}
$p = new Person("Ada", 36);
echo $p->describe() . "\n";<?php
$nums = [1, 2, 3, 4, 5];
$evens = array_filter($nums, fn($n) => $n % 2 === 0);
$doubled = array_map(fn($n) => $n * 2, $evens);
echo implode(", ", $doubled) . "\n";
echo "Sum: " . array_sum($nums) . "\n";<?php
enum Suit: string {
case Hearts = 'H';
case Spades = 'S';
public function color(): string {
return match($this) {
Suit::Hearts => 'red',
Suit::Spades => 'black',
};
}
}
echo Suit::Hearts->color() . "\n";The editor uses Monaco, the engine behind VS Code, with language-aware editing tools and familiar keyboard controls.
Type or paste your code into the editor, then click Run (or press Ctrl/Cmd + Enter) to execute it.
Output streams into the console panel, including runtime errors, exit status, and execution time.
Nothing to install and no account to create — code runs in an isolated hosted runtime.
Language-aware autocomplete and IntelliSense suggestions where the editor has a matching language service
Syntax highlighting, with native compiler and runtime errors shown in the console
Bracket matching, auto-indentation, code folding, and a minimap
Multi-cursor editing plus find & replace (Ctrl/Cmd + F)
Full undo/redo history and copy to clipboard
Built on Monaco — the same editor that powers VS Code
Run on demand, or turn on Auto-run to execute on every change
Stop long-running or infinite programs at any time
A real console shows standard output, errors, exit status, and execution time
Pass standard input (stdin) to your program from the Input panel — one value per line
Switch between light and dark themes
Adjust font size and other editor settings
Toggle side-by-side or top/bottom layouts
Enter distraction-free fullscreen mode
Generate a shareable link to your exact code in one click — no login needed
Your work autosaves to your browser, so you can pick up where you left off
Copy the active file to your clipboard
Run code: Ctrl/Cmd + Enter
Find & replace: Ctrl/Cmd + F
Open the full shortcut list from the keyboard icon in the toolbar
PHP is one of 23 linked-project compilers. Run always starts main.php; selecting a helper tab changes what you edit, not the entry file.
main.php requires the sibling PHP file before calling its function.
Linked-project languages (23): Node.js, TypeScript, Deno, Python, C, Go, Dart, Swift, Rust, Ruby, PHP, Java, Kotlin, C++, C#, Nim, Crystal, Haxe, Zig, Scala, D, Bun, Objective-C.
Single-file scratchpads (46): Matplotlib, NumPy, pandas, Haskell, Clojure, Perl, Lua, Tcl, jq, Raku, Elixir, Bash, Zsh, Nushell, R, Assembly (NASM), Julia, Octave, Groovy, PowerShell, Visual Basic .NET, Odin, Pascal, Lisp, Erlang, CoffeeScript, COBOL, BASIC, V, Racket, OCaml, Prolog, AWK, Emacs Lisp, Emojicode, Forth, F#, Fortran, Assembly (NASM64), Solidity, Mojo, Ada, WASM (WAT), Gleam, Shell Script (sh), Scheme. Their extra project files are not submitted to the runtime.
Download project exports every PHP tab and a README in one ZIP archive.