자바스크립트에서 escape 함수를 통해 데이터를 받을 경우 '%uC548%uB155%uD558%uC138%uC694' 형태의 문자열로 인코딩되어서 오게 됩니다.
PHP 에서는 unescape 함수가 없기 때문에 직접 만들어 주어 사용할 수 있습니다.
아래 코드를 참고 하세요


function tostring($text) {
return iconv('UTF-16LE', 'UTF-8', chr(hexdec(substr($text[1], 2, 2))).chr(hexdec(substr($text[1], 0, 2)))); // UTF-8 인 경우
// return iconv('UTF-16LE', 'UHC', chr(hexdec(substr($text[1], 2, 2))).chr(hexdec(substr($text[1], 0, 2)))); // EUC-KR 인 경우
}
function unescape($text){
return rawurldecode(preg_replace_callback('/%u([[:alnum:]]{4})/', 'tostring', $text));
}


처리할 문서가 charset euc-kr 일경우 함수 tostring 에서 iconv 2번째인자를 "UHC" 로
utf8 일경우 "UTF-8"로 지정한다.

예)

$escapeString = "%uC548%uB155%uD558%uC138%uC694"; // "안녕하세요"를 escape 한 문자열
$unEscapeString = unescape($escapeString);
echo $unEscapeString;

// 출력결과
// 안녕하세요

2010/02/11 20:34 2010/02/11 20:34

Trackback Address :: https://youngsam.net/trackback/999