Created
March 23, 2015 06:40
-
-
Save hongster/7beb229e482e0bfaaf90 to your computer and use it in GitHub Desktop.
Combine hex-to-string function with encoding conversion. In this example, the source string Unicode string encoded in hexadeciaml. The following code decodes it and convert it to UTF-8 string.
This file contains 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
<?php | |
function hexToStr($hex){ | |
$string=''; | |
for ($i=0; $i < strlen($hex)-1; $i+=2){ | |
$string .= chr(hexdec($hex[$i].$hex[$i+1])); | |
} | |
return $string; | |
} | |
$s = '6df157335e0253575c71533a53576d7759279053003100300037003953f7002000200068007400740070003a002f002f007700770077002e006700700073002e0063006f006d002f006d00610070002e0061007300700078003f006c00610074003d00320033002e0031003200330026006c006e0067003d003100310033002e003100320033'; | |
echo mb_convert_encoding(hexToStr($s), 'UTF-8', 'Unicode'); | |
// Output: 深圳市南山区南海大道1079号 http://www.gps.com/map.aspx?lat=23.123&lng=113.123 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment