Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active August 7, 2019 16:34
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 parzibyte/592fb5d037e56f94e855f95a69b1766f to your computer and use it in GitHub Desktop.
Save parzibyte/592fb5d037e56f94e855f95a69b1766f to your computer and use it in GitHub Desktop.
<?php
private function handleTextFrame($frameSize, $raw)
{
$data = unpack('C1encoding/A' . ($frameSize - 1) . 'information', $raw);
if ($data['encoding'] == 0x00) # ISO-8859-1
return mb_convert_encoding($data['information'], 'utf-8', 'iso-8859-1');
else{ # utf-16
# Fix the missing last char of the info bug
# Add NUL character at the end of the string.
# Don't ask, just enjoy. Idk why it works, but it works!
$data["information"] .= chr(0);
return mb_convert_encoding($data['information'], 'utf-8', 'utf-16');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment