Online PHP syntax checker / validator [closed]
Asked Answered
O

8

21

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

Thanks in advance!

Oller answered 11/3, 2011 at 6:4 Comment(7)
What kind of validation do you want ?Atworth
I would like one that would find the errors in my PHP script, display at which line the error is at, and possibly explain the error.Oller
Perhaps you could write your own? Just need to use php -l [filename] to parse the php file, and not execute it.Hairstyle
Why an online validator instead of using an IDE such as NetBeans or ZendStudio? I think a really inquisitive web developer would use a desktop validator instead of an online validator, I would not trust the later to be more reliable...Squiggle
@Hairstyle Could you explain in more detail what you just said?Oller
@Hairstyle is php -l [filename] a parsing as part of php's compiler?Dextrosinistral
Try phpsyntaxchecker.comEgon
H
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>
Hairstyle answered 11/3, 2011 at 6:43 Comment(2)
It being a security risk or not depends on where the file was uploaded.Groom
If you don't have php in your $PATH variable you can cd to the directory where php.exe exists and call php.exe -l C:\path\to\file.php.Dextrosinistral
C
7

I found this for online php validation:-

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

Hope this helps.

Cuspidor answered 11/3, 2011 at 6:10 Comment(0)
V
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/

Vaticinate answered 4/11, 2011 at 14:28 Comment(1)
When the file is too large, it throws Error 414 URI Too longIlluminate
J
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

Jumbuck answered 11/3, 2011 at 6:9 Comment(1)
first link is dead What ways are there to validate PHP code?Polysyllable
C
1

Ther's a new php code check online:

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

Classic answered 15/2, 2014 at 15:36 Comment(0)
K
1

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

I'm a novice, but it helped me.

Kinsella answered 17/9, 2015 at 16:59 Comment(1)
Already covered by Mario Lurig's answer.Distributary
C
0

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

http://trycodeonline.com

Commentate answered 25/6, 2013 at 12:55 Comment(3)
does not exist anymoreClassic
Try phpsyntaxchecker.comEgon
Try php online This tool allow you to check your php codes, execute, and share your code with fiends.Naturally
M
0

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

Muldoon answered 22/10, 2013 at 17:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.