title: Safely transport strings with special characters
body: <p>I have the following source file: <a href="https://www.post24.lv/public/files/Pakomatu%20adreses_web_lv.csv" rel="nofollow">https://www.post24.lv/public/files/Pakomatu%20adreses_web_lv.csv</a></p>
  
  <p>It's a list of addresses with lots of special characters (it's Latvian). I'm having lots of issues with this because the addresses get stored to a different file and then a database, so there's lots of transporting going on and the encoding seems to break somewhere.</p>
  
  <p>Is there a way in PHP that I can safely convert it to HTML entities so that it wouldn't break? I already tried doing <code>htmlentities($string)</code> but it gives the wrong entities for some chars.</p>
  
  <p>For example, the 3rd line should start with <code>Anniņmuižas RIMI pakomāts</code>, but <code>htmlentities($string, null, 'cp1252')</code> converts it to <code>Anni&amp;ograve;mui&amp;thorn;as RIMI pakom&amp;acirc;ts</code> which results in <code>Anniòmuiþas RIMI pakomâts</code>.</p>