0

This is my code:

<?php
        $a = array('chào','thân','ái','và','quyết','thắng');
    ?>
    <script>
        var abc = '<?php echo json_encode($a); ?>';
    </script>

When run and i got abc variable is:

var abc = '["ch\u00e0o","th\u00e2n","\u00e1i","v\u00e0","quy\u1ebft","th\u1eafng"]';

So, how to convert it's as before? i want to it's become

var abc = '["chào","thân","ái","và","quyết","thắng"]';
Erik Lieben
  • 1,249
  • 6
  • 12
Code Metal
  • 602
  • 2
  • 8
  • 19

2 Answers2

1

There might be you're answer here : How to decode Unicode escape sequences like "\u00ed" to proper UTF-8 encoded characters?

But why would you translate those escaped sequences, which should be well displayed and correctly translated by php (json_decode) and javascript (JSON.parse) ?

Community
  • 1
  • 1
0

If your php is >= 5.4, you can use the JSON_UNESCAPED_UNICODE flag to encode unicode characters as-is:

var abc = '<?php echo json_encode($a, JSON_UNESCAPED_UNICODE); ?>';

However, the escaped form works just fine and is less error-prone, so I'd suggest that you keep using it.

georg
  • 211,518
  • 52
  • 313
  • 390