2

I'm getting a list of people through a file_get_contents request and parsing that list.

While looping through them, if person passes some conditions I'll need to grab that persons data and creating a body for a post request.

But some of the values I'm getting contain different types of special characters. Like ü, æ, ø and so on. Whenever this happens the string is delivered as a binary string. Like: b"tæst". When these characters are not present it's delivered like "test".

array:14 [
  0 => "23468"
  1 => "Firstname"
  2 => b"Læstname"
  3 => "[email protected]"
  4 => "center"
  5 => "2016-11-29"
  6 => ""
  7 => ""
  8 => ""
  9 => ""
  10 => "Level"
  11 => "54698523"
  12 => ""
  13 => ""
]

After parsing the list, this is for example an array for one user. So when I wan't to do a string containing the users fullname I've tried something like:

htmlspecialchars($employee[1].' '.$employee[2], ENT_COMPAT,'ISO-8859-1', true);

But I need to returned this as json, and when I json_encode this it just returns false. I believe I've narrowed it down to the special character being responsible for it without knowing why.

So I suppose I'm asking what's happening here with the binary string in the json_encoding and is there a way I can convert that or do some other workaround to handle these special characters as well?

8
  • 1
    Which encoding is the document using? Commented Nov 30, 2016 at 14:22
  • I've tried to figured that out too but haven't been able to. Is there a way I can find that or do I need to ask the data supplier about that? Commented Nov 30, 2016 at 14:27
  • 1
    Just download the file, open it (for example) with notepad++ and have a look to the encoding menu :) Commented Nov 30, 2016 at 14:32
  • Well It's not a downloadable file I think. I just have a url that export and spits out this list as content. I think it's just csv and that's what I get through my file_get_contents. Commented Nov 30, 2016 at 14:38
  • 2
    How did you test it. What command spits out that format? fwiw a "binary" string is exactly the same as a normal string in php. There is no difference. It's an old artifact Commented Nov 30, 2016 at 15:17

1 Answer 1

3

Suddenly it worked just utf-8_encode the entire string after running the file_get_contents and that solved the issue.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.