Notes:
I have a mySql database containing 7000+ records. In a particular column they stored all the hex values represent its respective Unicode Character like above example. I need to search the database by passing hexvalue as my search string in order to get the above Unicode Character.
But overall, I’m not quite sure what you’re asking. If you’re trying to convert efbd81 to a unicode character, then you’re having problems because efbd81 isn’t a valid hex representation of a UTF-8 character. EF, BD and 81 are representations of three separate UTF-8 characters. EFB & D81 are valid hex representations of a UTF-8 character as well. If you need to convert EF, BD, 81, EFB or D81 to a unicode character, you would need to convert it to decimal first (http://php.net/manual/en/function.hexdec.php) and then you could use this function to convert it to a unicode character: http://ftzdomino.blogspot.com/2009/06/php-utf-8-chr-and-ord-equivalents.html.
In MySql Database, they 've a builtin function HEX(“ 黪 “). I use this functions to genarate hex value, For every unicode characters which is stored in varchar column collation utf8_unicode_ci. so i have an unique UTF-8 (hex) values for all the unicodes.
So i am looking for a function where by it can convert my input unicode characters to this format UTF-8 (hex) 0xEF 0xBD 0x81 (efbd81). so i would able to search any unicode character which is stored in the DB.
I apologize, I was wrong. However, I can’t find a way to do this using PHP. My only suggestion is to use MySQL itself for the conversion:
// if you're using PDO or mysqli, change the function names
$result = mysql_query('SELECT HEX(“ 黪 “)');
$row = mysql_fetch_row($result);
$hex = $row[0];
This is not a pretty or efficient solution, in my opinion. Maybe someone else has a better idea?
Thanks for everyone help. Done, Finally. Let me share with what I have. Following PHP functions works great for MySQL utf8_unicode_ci data conversion to UTF-8 (hex)
Conclusion:
Using JavaScript “encodeURI” to post value to php
In PHP request the above-submitted value with out any conversion.
Use the following functions to convert the request value
This will return UTF-8 (hex), that is the unique reference for the value in DATABASE