0

is there a way to check by using a command into terminal,recursively into folders, if a PHP file is corrupted? Thank you very much.

In my case, for corruption i mean bad encoding that could create problems with PHP interpreting.

5
  • 1
    If by "corrupted" you mean "PHP files with syntax errors", then you can use php -l. Commented Apr 17, 2014 at 18:41
  • 2
    unix.stackexchange.com/questions/15157/… Commented Apr 17, 2014 at 18:42
  • 1
    Define corrupted please! Sysntax errors? Semantical errors? bad encoding? Commented Apr 17, 2014 at 18:42
  • 1
    If your version control system says it's not the same as the one you checked out anymore? Commented Apr 17, 2014 at 18:44
  • In my case, for corruption i mean bad encoding that could create problems with PHP interpreting. Commented Apr 17, 2014 at 19:11

2 Answers 2

3

What do you mean by corrupted? I assume you mean syntax error?

You can check for syntax errors in a terminal with:

php -l file.php

You can use find to search recursively and check all php files:

find . -type f -name '*.php' -exec php -l {} \;

Hope this helps :)

Sign up to request clarification or add additional context in comments.

1 Comment

Worth noting you need to enable display_errors for CLI PHP to see detailed error message, otherwise all you get will be rather useless.
1

Problem was caused by the Byte Order Mark in my files. Used this answer to fix everything Elegant way to search for UTF-8 files with BOM?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.