Last active
August 8, 2017 03:09
-
-
Save hotta/91c25eb7cbc47f8d6aee to your computer and use it in GitHub Desktop.
Display data encoded as UTF-8 strings
This file contains hidden or 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
#!/usr/bin/php | |
<?php | |
//--------------------------------------------------------------------- | |
// Display data encoded as UTF-8 strings | |
// | |
// Usage: tail -f log-files-etc | cvtlog.php | |
//--------------------------------------------------------------------- | |
function pack_func($matches) // $matches[] = array('\xXX', '\xXX'); | |
{ | |
$tmp = sscanf('0' . substr($matches[0], 1), "%x"); | |
$digit = $tmp[0]; | |
$packed = pack('C', $digit); | |
return $packed; | |
} | |
while ($line = fgets(STDIN)) { | |
print preg_replace_callback('/\\\x[0-9a-f]{2}/', 'pack_func', $line); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment