Skip to content

Instantly share code, notes, and snippets.

@vvasabi
Created October 7, 2014 18:30
Show Gist options
  • Save vvasabi/b011cb997f30da1dd247 to your computer and use it in GitHub Desktop.
Save vvasabi/b011cb997f30da1dd247 to your computer and use it in GitHub Desktop.
Remove Photoshop gremlins. Use it like so: pbpaste | php antigremlin.php | pbcopy.
<?php
function remove_gremlins($str) {
$cleaned = '';
for ($i = 0, $max = strlen($str); $i < $max; $i++) {
$char_str = substr($str, $i, 1);
$char = ord($char_str);
if (($char >= 32) || ($char == 13)) { // new line or printable chars
$cleaned .= $char_str;
}
}
return $cleaned;
}
while($buffer = fgets(STDIN)){
echo remove_gremlins($buffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment