Verify file encoding with grep

List all lines in PHP-files in a directory-tree that contain characters out of the ASCII 7Bit pane:

~ grep -nPR --include=*.php [\xE0-\xFF] *

Does a quick and easy controlling on a full package of files quickly. Finds stuff like this or that.

Tip: If you run a project, specify upfront in which encoding files are provided. If you stick with UTF-8 do that w/o BOMs, you can look them up with grep as well. I worked in one company where three developers were looking for a bug in output for nearly a day until they realized that some BOM has been included in some PHP template … . grep can save you the day.

Related Ticket: #14735 – Encoding Issue in Files

This entry was posted in Hacking The Core, Hakre's Tips, Pressed and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.