Support the ongoing development of Laravel.io →
posted 10 years ago
Configuration

I have a problem in Laravel ..

When I use echo or print_r or var_dump my data (retrieved from eloquent) are printed in the right format (UTF-8, greek language). But when I use " return Response::json($data) "

returns something like:

"\u0395\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03bf\u03af \u03c7\u03b1\u03c1\u03b1\u03ba\u03c4\u03ae\u03c1\u03b5\u03c2"

I have already set UTF-8 as default charset in my php.ini, mysql.conf (but this is not the problem).

I have tried several ways to set the charset like:

Response::json($data,200,$headers) --> where $headers is an array with:

'Content-type'=> 'application/json; charset=utf-8'

Also tried to add charset inside laravel's response.php but nothing changes...

My operating system is Debian 7 wheezy 64bit, PHP version 5.5.13 , MySQL 5.6.19 and apache2 server.

Last updated 2 years ago.
0

They are converted characters. There shouldn't be a problem if you decode it or use it in javascript.

Last updated 2 years ago.
0

gcreator, for a more complete comprehension what's going on

  1. open http://www.php.net/manual/en/json.constants.php
  2. take a look at 'JSON_UNESCAPED_UNICODE'
    then follow the chain
    3.1 http://laravel.com/api/source-class-Illuminate.Support.Facades.Response.html#_json
    3.2 http://laravel.com/api/source-class-Illuminate.Http.JsonResponse.html#JsonResponse
  3. ...
  4. profit?
Last updated 2 years ago.

ebedy liked this reply

1

brilliant answers!! Thank you all!!!

I have just changed a little bit the Response::json like:

Response::json($data,200,$headers,JSON_UNESCAPED_UNICODE);

and works like a charm!!!!!!

Thank you!!!!

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

gcreator gcreator Joined 9 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.