Guest User

Untitled

a guest
Jun 25th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. <?php
  2. // In PHP 5.4 you can pass JSON_UNESCAPED_UNICODE and JSON_UNESCAPED_SLASHES to json_encode:
  3. $input = array('file' => '/\intro_cropsic – .m4v');
  4. $paramsString = json_encode($input, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
  5.  
  6. // And that will encode arrays with unicode characters more compatible with JavaScript.
  7. // (e.g. it will produce the same sha1 if you phpjs.utf8_encode paramString in JavaScript )
  8.  
  9. // On PHP 5.3 and lower, you may want to try
  10. function json_encode_noescape_slashes_unicode ($arr) {
  11. array_walk_recursive($arr, function (&$item, $key) {
  12. if (is_string($item)) {
  13. $item = mb_encode_numericentity($item, array(0x80, 0xffff, 0, 0xffff), 'UTF-8');
  14. }
  15. });
  16.  
  17. $str = mb_decode_numericentity(json_encode($arr), array(0x80, 0xffff, 0, 0xffff), 'UTF-8');
  18. $str = str_replace('\/','/', $str);
  19.  
  20. return $str;
  21. }
Add Comment
Please, Sign In to add comment