2
[7671] => Sleaford Carre’s

is an element in $result

$result=  json_encode($result);
echo $result;
//outputs
"7671":null,

Please note that this is not a normal apostrophe (single quote) or a back tick. I cant even find it on my keyboard. Data comes from a Latin-1 table.

I have also noticed that using htmlentities on building the array will dissapear the string from the array. What am I to do??

user138720
  • 141
  • 8
  • 3
    have you tried to encode everything in UTF-8 first? This will solve many issues like this. – STT LCU Oct 30 '13 at 16:26
  • 2
    `json_encode()` expects UTF-8 encoded data. – Ben Fortune Oct 30 '13 at 16:27
  • I'd seriously look at transferring the data to a table that supports a modern encoding. Using 1990s legacy encodings is just asking for trouble. – Quentin Oct 30 '13 at 16:30
  • Try to encode your string to UTF-8 first. Check this: http://php.net/manual/en/function.utf8-encode.php --- (utf8_encode function) – briosheje Oct 30 '13 at 16:30
  • as the others have said, use utf8_encode() then json_encode(). – Brian Oct 30 '13 at 16:34
  • using utf_encode() on building the array gives me `"7671":"Sleaford Carre\u0092s` That'll probably do it. thanks guys. Don't know how that data got entered! – user138720 Oct 30 '13 at 16:37
  • Anyone want a green tick? I'll give you 10 mins. @quentin if I had a choice about legacy stuff, I wouldn't be using windows+sqlServer! – user138720 Oct 30 '13 at 16:44

1 Answers1

4

As no-one has actually written an answer, read the comments:)

as the others have said, use utf8_encode() then json_encode(). – Brian

user138720
  • 141
  • 8