title: PHP: Transform incoming string to UTF-8, without any information what encoding it was
body: <p>I'm having problems.</p>
  
  <p>I have a REST API that uses json_encode to output data as JSON. However, sometimes data gets pushed to the API that is not UTF-8 data. And so when trying to output this data, json_encode throws an exception, because it can only handle UTF-8 data.</p>
  
  <p>What should I do? Can I somehow force every incoming data to be UTF8? This seems to be hard, because I have no information what encoding the data is sent in.</p>
  
  <p>Or should I try to run json_encode on the incoming data and if it can not encode return an error?</p>
  
  <p>EDIT: I forgot to mention that this is a REST API. So I get POST requests to my API with lots of fields and values.</p>