Currency Symbols to Numerical Encoding
I m having many currency symbols. i want to convert them to numerical unicode like £ to £ as I need to extract this n开发者_如何学运维umber 163 and use it.
Thanks in Advance.
Some people already implemented "uniord" ;)
function uniord($c) {
$h = ord($c{0});
if ($h <= 0x7F) {
return $h;
} else if ($h < 0xC2) {
return false;
} else if ($h <= 0xDF) {
return ($h & 0x1F) << 6 | (ord($c{1}) & 0x3F);
} else if ($h <= 0xEF) {
return ($h & 0x0F) << 12 | (ord($c{1}) & 0x3F) << 6
| (ord($c{2}) & 0x3F);
} else if ($h <= 0xF4) {
return ($h & 0x0F) << 18 | (ord($c{1}) & 0x3F) << 12
| (ord($c{2}) & 0x3F) << 6
| (ord($c{3}) & 0x3F);
} else {
return false;
}
}
What's wrong with simply using ord
function?
$symbol = "£";
$code = ord($symbol); //should return 163
URL Encode gives you everything in hexidecimal format, but when converted to an int, it gives you the UTF-8 char code without the need for workarounds.
<?php echo hexdec(substr(urlencode('£'), -2, 2)); ?>
EDIT
Perhaps mb_string
could help with your encoding issues.
In case you only want to replace some characters in a string, use the replac function: http://php.net/manual/en/function.str-replace.php
EDIT: For this you need to know the codes beforehand, but you can find most here: http://w3schools.com/tags/ref_entities.asp
And dollar, that isn't in that list, is &# 36;
精彩评论