What this PHP editor does, and what it does not
This is a browser-based editor for writing and reading PHP, not a PHP sandbox. Your code is never executed: not in the browser and not on our server. What you get is a CodeMirror 5 editor in PHP mode with line numbers, bracket matching, automatic closing of brackets and quotes, and folding of functions, classes, and arrays from the gutter. Because the mode understands mixed files, HTML outside the PHP tags is highlighted as HTML, including any embedded CSS and JavaScript.
The toolbar lets you download the file as code.php, copy it, import a .php file or a URL, and switch themes. There is no formatter, linter, or autocomplete. Your code is kept in this browser's localStorage, saved every two minutes and when you press Ctrl + S.
Worked example: write here, run locally
A typical use is drafting or cleaning up a small script, such as a report over an array of orders:
<?php
declare(strict_types=1);
$orders = [
['id' => 101, 'customer' => 'Ada', 'total' => 49.5, 'status' => 'paid'],
['id' => 102, 'customer' => 'Linus', 'total' => 20.0, 'status' => 'pending'],
['id' => 103, 'customer' => 'Grace', 'total' => 1250.75, 'status' => 'paid'],
];
$paid = array_filter($orders, fn(array $o): bool => $o['status'] === 'paid');
usort($paid, fn(array $a, array $b): int => $b['total'] <=> $a['total']);
foreach ($paid as $order) {
printf("#%d %-6s %10s\n", $order['id'], $order['customer'], number_format($order['total'], 2));
}
echo 'Paid total: ' . number_format(array_sum(array_column($paid, 'total')), 2) . PHP_EOL;
Click Download, save it as report.php, and run php report.php in a terminal. With PHP 8.2 the output is:
#103 Grace 1,250.75
#101 Ada 49.50
Paid total: 1,300.25
To check syntax without running anything, use php -l report.php. To serve a page with HTML, run php -S localhost:8000 in the folder and open http://localhost:8000/report.php. The file above has no closing ?> on purpose, as explained below.
PHP mistakes worth catching before you upload
Missing semicolon, error on the next line
$name = "Ada"
echo $name;
PHP 8 reports Parse error: syntax error, unexpected token "echo" ... on line 3. The error line is where PHP noticed the problem, so always check the end of the line above it.
Single quotes do not interpolate
$qty = 3;
echo "Qty: $qty items"; // Qty: 3 items
echo 'Qty: $qty items'; // Qty: $qty items
Variables and escapes like \n only work inside double quotes or heredoc. The editor colors variables inside double-quoted strings differently, which helps spot this.
Reading an array key that may not exist
$user = ['name' => 'Ada'];
echo $user['email'];
// Warning: Undefined array key "email"
Use a default with the null coalescing operator: $user['email'] ?? ''. The same applies to $_GET and $_POST.
Loose comparisons
var_dump("1" == "01"); // bool(true)
var_dump("10" == "1e1"); // bool(true)
var_dump(0 == "abc"); // bool(false) in PHP 8, bool(true) in PHP 7
Numeric strings are compared as numbers, and the rules changed in PHP 8. Use === for IDs, tokens, and anything a user typed.
Output before headers
A blank line before <?php, or after a closing ?> in an included file, is sent to the browser as output. A later header('Location: ...') then fails with "Cannot modify header information, headers already sent". Leave out the closing tag in files that contain only PHP.
Limitations
- No execution, no
php -l style syntax check, and no error messages. Highlighting is the only feedback.
- No code formatting, no autocomplete, and no find and replace inside the editor.
- Code outside
<?php ... ?> is treated as HTML, so a file pasted without its opening tag will not be highlighted as PHP.
- Import URL fetches the file from your browser. A URL that points to a live
.php page returns that page's HTML output, not its source code.
When to use a different tool
- To preview the HTML a PHP template would produce, paste that HTML into the HTML Code Editor.
- To check a JSON string built with
json_encode, use the JSON Validator.
- To tidy a SQL query before putting it in a prepared statement, use the SQL Formatter.
- To turn text into safe HTML entities (what
htmlspecialchars does), use the HTML Encoder.
Frequently asked questions
Can I run PHP code in this editor?
No. The editor runs entirely in your browser and PHP needs a PHP interpreter, so nothing you type is executed, here or on our server. Download the file and run it locally with php file.php, or start the built-in server with php -S localhost:8000 in the file's folder.
Does the PHP editor check my syntax?
No. It highlights syntax, which makes an unclosed string or missing brace easy to spot, but it does not parse or lint the code. Run php -l file.php on your machine to check syntax without executing the script.
Why is part of my code highlighted like HTML?
The editor uses PHP mode with embedded HTML, just like a .php file on a server. Anything before <?php, or after a closing ?>, is treated as HTML. If your code is colored as plain text, the opening <?php tag is probably missing.
Why does PHP report a parse error on the wrong line?
PHP reports the line where it found the unexpected token, which is often the line after the real mistake. A missing semicolon at the end of line 2 is reported as unexpected token on line 3. Look at the end of the previous line first.
Should I end a PHP file with ?>
Not in files that contain only PHP. Any space or blank line after the closing tag is sent to the browser as output, which can trigger "headers already sent" warnings when you later call header() or setcookie(). PSR-12 recommends omitting the closing tag in pure PHP files.