21

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

Thanks in advance!

Seth McClaine
  • 9,142
  • 6
  • 38
  • 64
Web_Designer
  • 72,308
  • 93
  • 206
  • 262

8 Answers8

33

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>
Jacob
  • 8,278
  • 1
  • 23
  • 29
7

I found this for online php validation:-

http://www.icosaedro.it/phplint/phplint-on-line.html

Hope this helps.

Mukesh Chapagain
  • 25,063
  • 15
  • 119
  • 120
5

Here's one more for you that not only performs the php -l check for you, but also does some secondary analysis for mistakes that would not be considered invalid (e.g. declaring a variable with a double equal sign).

http://phpcodechecker.com/

Seth McClaine
  • 9,142
  • 6
  • 38
  • 64
Mario Lurig
  • 783
  • 1
  • 6
  • 16
4

Here is a similar question to yours. (Practically the same.)

What ways are there to validate PHP code?

Edit

The top answer there suggest this resource:

http://www.meandeviation.com/tutorials/learnphp/php-syntax-check/v4/syntax-check.php

Community
  • 1
  • 1
Flipper
  • 2,589
  • 3
  • 24
  • 32
1

Ther's a new php code check online:

http://www.piliapp.com/php-syntax-check/

StarsSky
  • 6,721
  • 6
  • 38
  • 63
1

http://phpcodechecker.com/ performs syntax check and a custom check for common errors.

I'm a novice, but it helped me.

Mark Gavagan
  • 878
  • 12
  • 45
0

Here is also a good and simple site to check your php codes and share your code with fiends :

http://trycodeonline.com

Rohitashv Singhal
  • 4,517
  • 13
  • 57
  • 105
0

In case you're interested, an offline checker that does complicated type analysis: http://strongphp.org It is not online however.

mutewitness
  • 166
  • 1
  • 4