Skip to content

Instantly share code, notes, and snippets.

@vip3r011
Created March 20, 2021 07:50
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 vip3r011/ac9a0d2ec46b4b9ae99a5ffe13f5bf33 to your computer and use it in GitHub Desktop.
Save vip3r011/ac9a0d2ec46b4b9ae99a5ffe13f5bf33 to your computer and use it in GitHub Desktop.
hex to string in PHP
<?php
function hex_to_string ($hex) {
if (strlen($hex) % 2 != 0) {
throw new Exception('String length must be an even number.', 1);
}
$string = '';
for ($i = 0; $i < strlen($hex) - 1; $i += 2) {
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
}
return $string;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment