1. Home
  2. Developer
  3. PHP Syntax Checker

PHP Syntax Checker

Find common PHP syntax slips with line and column positions.

For every format and option in one place, use Code Formatter and Checker →

Runs in your browser · No upload
This is a rule-based quick check, not a PHP parser, and it does not replace php -l. Passing does not mean the code runs, and the missing-semicolon and = versus == notes can be false alarms on valid code.
Used to decide whether a function is deprecated or removed.
Lines
14
PHP blocks
1
Errors
2
Warnings
2
Notes
1
PHP code
TypeLocation (line:col)MessageLine
Warning2:14The statement seems to end without a semicolon (;). A new statement starts right after it.$name = 'Kim'
Warning5:12This if condition assigns with =. If you meant to compare, use == or ===. The assigned value becomes the condition result.if ($count = 5) {
Note7:3else if works with braces but nests the if one level deeper than elseif. elseif is the usual choice.} else if ($count > 1) {
Error11:9mysql_connect was removed in PHP 7.0 and fails on the selected version. Use mysqli_* / PDO instead.$conn = mysql_connect('localhost', 'user', 'pass');
Error13:22The opening { has no matching closing bracket.function greet($who) {

Your code is checked in this browser only and never sent to a server.

How to use

  1. Paste the PHP code you want to check into the input box. It starts with a sample that contains a few slips.
  2. Pick the target PHP version. Removed and deprecated functions are judged against it, and your choice is remembered in this browser.
  3. Read the errors, warnings and notes in the result table, each with a line:column position and the line itself.
  4. Fix the code and the table updates immediately. An unclosed string or comment hides everything below it, so start from the first row.

This tool is not a full PHP parser. It reads tags, strings, comments and brackets with its own tokenizer and applies a handful of rules. It does not replace php -l, and passing this check does not mean the code runs. It does not check whether variables or functions are defined, or whether types match.

What it checks

Group Check Level
Tags no whitespace after <?php, short tag <?, no PHP tag at all, <?xml declaration error, warning, note
Output whitespace or BOM before <?php, blank lines left after ?> warning
Termination unclosed single quote, double quote, backtick, heredoc, nowdoc or /* */ comment error
Brackets unmatched ( ), [ ], { }, including attributes #[ ] error
Semicolons places where a ; looks missing (end of line, end of file) warning
Compare and assign assignment inside a condition such as if ($a = 5), a bare $a == 1; statement warning, note
Control flow else if (an error with the colon syntax), an empty body as in if (...); note, error, warning
Paste problems smart quotes, invisible spaces such as U+00A0, a $ with no name error, warning
Deprecated mysql_*, ereg, split, create_function, each, money_format, strftime, utf8_encode and more error, warning, note

Sample result

Checking the sample in the input box against PHP 8.3 gives 2 errors, 2 warnings and 1 note.

  • Line 2, column 14: no semicolon after $name = 'Kim' (warning)
  • Line 5, column 12: = assigns inside the if ($count = 5) condition (warning)
  • Line 7, column 3: else if nests differently from elseif (note)
  • Line 11, column 9: mysql_connect was removed in PHP 7.0; use mysqli_* or PDO (error)
  • Line 13, column 22: the opening { of function greet($who) { is never closed (error)

Deprecated and removed functions depend on the version

Function Deprecated Removed Use instead
mysql_* 5.5 7.0 mysqli_*, PDO
create_function, each 7.2 8.0 closures, foreach
money_format 7.4 8.0 NumberFormatter
strftime, gmstrftime 8.1 not yet date(), IntlDateFormatter
utf8_encode, utf8_decode 8.2 not yet mb_convert_encoding()

For example, money_format is a warning when the target is 7.4 and an error from 8.0, while strftime reports nothing up to 8.0 and becomes a warning from 8.1. Methods such as $o->each() and functions you define yourself are skipped.

Where false alarms can happen

  • Missing semicolon candidates only look at the shape “a line ends with a value and a new statement starts next”. Lines that start with an operator (., ->, ?, and) and the line after if (...) are skipped, but unusual formatting can still flag valid code.
  • = versus == candidates list idioms such as if ($row = fetch()) only as a note. Only an assignment of a literal, like if ($a = 5), becomes a warning.
  • In template files, ?> counts as a statement end, so a missing final semicolon is not reported.
  • When a string is not closed, everything below it is unreadable and later problems stay hidden.

Frequently asked questions

How is this different from php -l?

php -l uses the real PHP parser, so it is exact. This tool is for places without PHP installed, to catch quotes, brackets and common slips quickly. Even after it passes, run php -l as well.

Why do I get “headers already sent”?

Whitespace or a BOM before <?php, or blank lines after ?>, is sent as output, so the response starts before header() or session_start() runs. This tool warns about both. In pure PHP files, leaving out the closing ?> avoids the trailing whitespace problem.

Where should I look for “unexpected end of file”?

Usually a { or ( was never closed, or a string never ended. The “has no matching closing bracket” rows point to where the bracket was opened, so start at that line.

A missing semicolon candidate shows up on valid code.

Candidates are estimated from rules and can be wrong. Look at the end of that line and the start of the next to see whether the statement really ended. When unsure, trust the php -l result.

Related tools: SQL Syntax Checker, HTML Validator, JavaScript Beautifier & Minifier, XML Validator, Regex Tester, Text Diff.

Your code is processed in your browser and never sent to a server.

Can't find the tool you need?

Tell us what you want to do. We build the most requested tools first.