From 74b768f77c614ea6f53409da0822c7c5b5ead1af Mon Sep 17 00:00:00 2001 From: Nicolas Martignoni Date: Fri, 13 Jul 2018 17:18:38 +0200 Subject: [PATCH] Function convert_hex_string() added. Issue #32. --- classes/local/utils.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/classes/local/utils.php b/classes/local/utils.php index b8ddb00..d36ba83 100644 --- a/classes/local/utils.php +++ b/classes/local/utils.php @@ -152,4 +152,17 @@ public static function get_wireless_interface_name() { return explode('/', array_keys(iterator_to_array($iter))[0])[4]; } + /** + * Convert string with hexadecimal code to unicode string. + * See https://stackoverflow.com/a/12083180. + * + * @param string $string to convert + * @return string converted + */ + public static function convert_hex_string($string) { + return preg_replace_callback('#\\\\x([[:xdigit:]]{2})#ism', function($matches) { + return chr(hexdec($matches[1])); + }, $string); +} + }