diff options
author | ctrlaltca <ctrlaltca@gmail.com> | 2014-07-19 17:18:36 +0200 |
---|---|---|
committer | ctrlaltca <ctrlaltca@gmail.com> | 2014-07-19 17:18:36 +0200 |
commit | 9c2824b1b752f26cc2bea0667a7ee2c7bbf26db0 (patch) | |
tree | 7ae661d70320fe29649929bf793cc7e96547e38a /framework/Web | |
parent | 071f22c5c038c962823af003a28663d0d2734a16 (diff) | |
parent | 8e07d0781150206fae722d9b9dcbdafd727665f6 (diff) |
Merge pull request #525 from david0/issue-524
Convert encoding of all values inside an array before json_serialize
Diffstat (limited to 'framework/Web')
-rw-r--r-- | framework/Web/Javascripts/TJavaScript.php | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/framework/Web/Javascripts/TJavaScript.php b/framework/Web/Javascripts/TJavaScript.php index f55b5c5b..3684132b 100644 --- a/framework/Web/Javascripts/TJavaScript.php +++ b/framework/Web/Javascripts/TJavaScript.php @@ -217,7 +217,6 @@ class TJavaScript else return ''; } - /** * Encodes a PHP variable into javascript string. * This method invokes json_encode to perform the encoding. @@ -226,16 +225,32 @@ class TJavaScript */ public static function jsonEncode($value, $options = 0) { - if (is_string($value) && - ($g=Prado::getApplication()->getGlobalization(false))!==null && - strtoupper($enc=$g->getCharset())!='UTF-8') - $value=iconv($enc, 'UTF-8', $value); + if (($g=Prado::getApplication()->getGlobalization(false))!==null && + strtoupper($enc=$g->getCharset())!='UTF-8') { + self::convertToUtf8($value, $enc); + } + $s = @json_encode($value,$options); self::checkJsonError(); return $s; } /** + * Encodes an string or the content of an array to UTF8 + * @param string|array|mixed $value + * @param string $sourceEncoding + */ + private static function convertToUtf8(&$value, $sourceEncoding) { + if(is_string($value)) + $value=iconv($sourceEncoding, 'UTF-8', $value); + else if (is_array($value)) + { + foreach($value as &$element) + self::convertToUtf8($element, $sourceEncoding); + } + } + + /** * Decodes a javascript string into PHP variable. * This method invokes json_decode to perform the decoding. * @param string string to be decoded |