Skip to content

Instantly share code, notes, and snippets.

View develop-maruku's full-sized avatar

develop-maruku

View GitHub Profile
@joni
joni / STRINGDECODE.sql
Created June 19, 2012 19:35
STRINGDECODE: MySQL function to decode unicode escapes to utf8
CREATE FUNCTION STRINGDECODE(str TEXT CHARSET utf8)
RETURNS text CHARSET utf8 DETERMINISTIC
BEGIN
declare pos int;
declare escape char(6) charset utf8;
declare unescape char(3) charset utf8;
set pos = locate('\\u', str);
while pos > 0 do
set escape = substring(str, pos, 6);
set unescape = char(conv(substring(escape,3),16,10) using ucs2);
@aeurielesn
aeurielesn / util.php
Created July 31, 2011 03:47
Decode Unicode strings in PHP
<?php
#source: http://stackoverflow.com/questions/2934563/how-to-decode-unicode-escape-sequences-like-u00ed-to-proper-utf-8-encoded-char
function replace_unicode_escape_sequence($match) {
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
}
function unicode_decode($str) {
return preg_replace_callback('/\\\\u([0-9a-f]{4})/i', 'replace_unicode_escape_sequence', $str);
}