-function js_unescape($source, $iconv_to = 'UTF-8') {
- $decodedStr = '';
- $pos = 0;
- $len = strlen ($source);
- while ($pos < $len) {
- $charAt = substr ($source, $pos, 1);
- if ($charAt == '%') {
- $pos++;
- $charAt = substr ($source, $pos, 1);
- if ($charAt == 'u') {
- // we got a unicode character
- $pos++;
- $unicodeHexVal = substr ($source, $pos, 4);
- $unicode = hexdec ($unicodeHexVal);
- $decodedStr .= code2utf($unicode);
- $pos += 4;
- }
- else {
- // we have an escaped ascii character
- $hexVal = substr ($source, $pos, 2);
- $decodedStr .= chr (hexdec ($hexVal));
- $pos += 2;
- }
- }
- else {
- $decodedStr .= $charAt;
- $pos++;
- }
- }
+function js_unescape( $source, $iconv_to = 'UTF-8' ) {
+ $decodedStr = '';
+ $pos = 0;
+ $len = strlen ( $source );
+
+ while ( $pos < $len ) {
+ $charAt = substr ( $source, $pos, 1 );
+ if ( $charAt == '%' ) {
+ $pos++;
+ $charAt = substr ( $source, $pos, 1 );
+
+ if ( $charAt == 'u' ) {
+ // we got a unicode character
+ $pos++;
+ $unicodeHexVal = substr ( $source, $pos, 4 );
+ $unicode = hexdec ( $unicodeHexVal );
+ $decodedStr .= code2utf( $unicode );
+ $pos += 4;
+ } else {
+ // we have an escaped ascii character
+ $hexVal = substr ( $source, $pos, 2 );
+ $decodedStr .= chr ( hexdec ( $hexVal ) );
+ $pos += 2;
+ }
+ } else {
+ $decodedStr .= $charAt;
+ $pos++;
+ }
+ }
+
+ if ( $iconv_to != "UTF-8" ) {
+ $decodedStr = iconv( "utf-8", $iconv_to, $decodedStr );
+ }