Created
May 29, 2015 11:03
-
-
Save tistre/40277b47155b7f5a678c to your computer and use it in GitHub Desktop.
Check files for Unicode U+00A0 No-Break Space
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Find invisible non-breaking spaces in source code | |
// which can cause errors in PHP and JavaScript. | |
// | |
// see: http://www.strehle.de/tim/weblog/archives/2013/02/26/1563 | |
// | |
// Usage: | |
// php charcheck.php path/to/*.php | |
// or: | |
// find path/to -name '*.php' | php charcheck.php - | |
function checkFile($filename) | |
{ | |
// "| ": space after pipe (c2 a0) | |
$check = chr(194) . chr(160); | |
$lines = file($filename); | |
$matches = array(); | |
foreach ($lines as $lineno => $line) | |
{ | |
if (strpos($line, $check) !== false) | |
{ | |
$matches[ ] = ($lineno + 1); | |
} | |
} | |
if (count($matches) > 0) | |
{ | |
printf("%s %s\n", $filename, implode(',', $matches)); | |
} | |
} | |
if ($argv[ 1 ] === '-') | |
{ | |
while (! feof(STDIN)) | |
{ | |
$filename = trim(fgets(STDIN)); | |
if ($filename !== '') | |
{ | |
checkFile($filename); | |
} | |
} | |
} | |
else | |
{ | |
for ($i = 1; $i < $argc; $i++) | |
{ | |
checkFile($argv[ $i ]); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
브레이크 없음 [심심이쉘]