Last active
August 29, 2015 14:17
-
-
Save hongster/27e9b7d860fa34b306fb to your computer and use it in GitHub Desktop.
PHP encodes string in UTF-8. This code converts it to Unicode, and then represent it as hexadecimal.
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 strToHex($string){ | |
$hex = ''; | |
for ($i=0; $i<strlen($string); $i++){ | |
$ord = ord($string[$i]); | |
$hexCode = dechex($ord); | |
$hex .= substr('0'.$hexCode, -2); | |
} | |
return $hex; | |
} | |
$s = '深圳市南山区南海大道1079号 http://www.gps.com/map.aspx?lat=23.123&lng=113.123'; | |
$s = mb_convert_encoding($s, 'Unicode', 'UTF-8'); | |
echo strToHex($s); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment