-1

I'm trying to get a json file with file_get_contents and it works fine, the only problem is some of the data returns with special characters instead of their actual data. ie '...' becomes '…'

I can fix this by outputting the data wrapped in htmlentities tags but I'd rather not do that and instead have the encoding fixed.

I've tried a few things to send headers but still I get the problem.

Carlo
  • 3
  • 4

1 Answers1

0

This simply means that you are outputting perfectly fine UTF-8 to the browser, but the browser is interpreting it as Latin-1 encoded instead. You need to correctly tell the browser that it should deal with the content as UTF-8 by setting appropriate headers:

header('Content-Type: text/html; charset=utf-8');

If that doesn't work, inspect the raw response including headers in the browser to see whether the headers are actually being set. See https://stackoverflow.com/a/8028987/476.
Also see Handling Unicode Front To Back In A Web App.

Community
  • 1
  • 1
deceze
  • 510,633
  • 85
  • 743
  • 889