Skip to content

Instantly share code, notes, and snippets.

@hotta
Last active August 8, 2017 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hotta/91c25eb7cbc47f8d6aee to your computer and use it in GitHub Desktop.
Save hotta/91c25eb7cbc47f8d6aee to your computer and use it in GitHub Desktop.
Display data encoded as UTF-8 strings
#!/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