rocafreestyler Posted September 25, 2007 Share Posted September 25, 2007 i have a function that returns a value in Unicode format. When I try and make a MySQL select statement with the Unicoce value it does not work. So I need to change this Unicode value into a ASCII value that I can use in my database query. Any help would be greatly appeciacted Regards Quote Link to comment https://forums.phpfreaks.com/topic/70607-convert-unicode-value-to-ascii-value-for-use-in-query/ Share on other sites More sharing options...
MadTechie Posted September 25, 2007 Share Posted September 25, 2007 erm... i don't understand what your trying to do, but mySQL supports Unicode have you got the correct CHARACTER SET and COLLATE ? ie CHARACTER SET utf8 COLLATE utf8_general_ci; do you have a example ? Quote Link to comment https://forums.phpfreaks.com/topic/70607-convert-unicode-value-to-ascii-value-for-use-in-query/#findComment-354806 Share on other sites More sharing options...
rocafreestyler Posted September 25, 2007 Author Share Posted September 25, 2007 function NC_DecryptString($key, $encryptedString) { // is the mcrypt extension installed? if (!extension_loaded('mcrypt')) { return false; } // first, convert the HEX-Encoded string to real characters $deHexedString = ""; $originalStringLength = strlen($encryptedString); if (($originalStringLength % 2) != 0) { return false; } for ($i = 0 ; $i < $originalStringLength ; $i += 2) { list($value) = sscanf(substr($encryptedString, $i, 2), "%x"); $deHexedString .= chr($value); } // make sure the key isn't too long; $key = substr($key, 0, 56); // prepare to decrypt $td = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_CBC, ''); $iv = str_repeat(chr(0), ; mcrypt_generic_init($td, $key, $iv); // decrypt the data return mdecrypt_generic($td, $deHexedString); } // Test decrypting data. $s = NC_DecryptString("Some magic key", "DA3111ED52E51A3E8A0AA734C833799D7074730274D9F8C6A561423CC9AB2C7C"); if ($s !== false) { echo $s . '<br>'; echo 'Length: ' . strlen($s) . '<br>'; for ($i = 0 ; $i < strlen($s) ; $i++) { echo ord($s[$i]) . ' '; } } else { echo "There was a failure."; } echo '<hr>'; The output of NC_DecryptString is Unicode. I think the reason that it is not working is because of null values in the string that I need to strip out. So the value i receive back from this function does not work in my mySQL query, but if I save the string it appears correct but if I do a strLen on it it is over double the length I would expect Cheers Cheers Quote Link to comment https://forums.phpfreaks.com/topic/70607-convert-unicode-value-to-ascii-value-for-use-in-query/#findComment-354815 Share on other sites More sharing options...
MadTechie Posted September 25, 2007 Share Posted September 25, 2007 if you have extra characters then your not encoding it correctly, either in the html or the database (i guess it could just be a font issule), if the that function fails when no $encryptedString is passed just an error check! e.g. if (empty($encryptedString)) return false; Quote Link to comment https://forums.phpfreaks.com/topic/70607-convert-unicode-value-to-ascii-value-for-use-in-query/#findComment-354820 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.