Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Online PHP syntax checker / validator [closed]

Tags:

Could someone refer me to an online PHP validator? It would be of much help.

Thanks in advance!

like image 332
Web_Designer Avatar asked Mar 11 '11 06:03

Web_Designer


People also ask

How to validate php code online?

To check your code, you must copy and paste, drag and drop a PHP file or directly type in the "PHP code" online editor below, and click on "Check PHP syntax" button. You can see the user guide to help you to use this php checker tool.

Which command can you run on a script named Clients php to check if there are any syntax errors in the file?

The “-l” or “–syntax-check” argument performs a syntax check on the given PHP file. Example 1: The following PHP Code is without Syntax error.


1 Answers

To expand on my comment.

You can validate on the command line using php -l [filename], which does a syntax check only (lint). This will depend on your php.ini error settings, so you can edit you php.ini or set the error_reporting in the script.

Here's an example of the output when run on a file containing:

<?php
echo no quotes or semicolon

Results in:

PHP Parse error:  syntax error, unexpected T_STRING, expecting ',' or ';' in badfile.php on line 2

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in badfile.php on line 2

Errors parsing badfile.php

I suggested you build your own validator.

A simple page that allows you to upload a php file. It takes the uploaded file runs it through php -l and echos the output.

Note: this is not a security risk it does not execute the file, just checks for syntax errors.

Here's a really basic example of creating your own:

<?php
if (isset($_FILES['file'])) {
    echo '<pre>';
    passthru('php -l '.$_FILES['file']['tmp_name']);
    echo '</pre>';
}
?>
<form action="" method="post" enctype="multipart/form-data">
    <input type="file" name="file"/>
    <input type="submit"/>
</form>
like image 82
Jacob Avatar answered Sep 27 '22 17:09

Jacob