title: Calling Php Script with UTF-8 POST variables
body: <p>AS3 documentation says that Strings in AS3 are in UTF-16 format.</p>
  
  <p>There is a textbox on a Flash Clip where user can type some data.</p>
  
  <p>When a button is clicked, I want this data to be sent to a php script.</p>
  
  <p>I have everything set up, but it seems that the PHP script gets the data in UTF-16 format. The data in the database (which is utf-8) shows some unrecognizable characters (where special characters are used), meaning that the data has not been sent in a correct encoding.</p>
  
  <pre><code>var variables:URLVariables=new URLVariables;
  
  var varSend:URLRequest=new URLRequest("http://website.com/systematic/accept.php");
  varSend.method=URLRequestMethod.POST;
  varSend.data=variables;
  
  var varLoader:URLLoader=new URLLoader;
  varLoader.dataFormat=URLLoaderDataFormat.VARIABLES;
  varLoader.addEventListener(Event.COMPLETE, completeHandler);
  </code></pre>
  
  <p>When submit button is clicked, the following handler gets executed.</p>
  
  <pre><code>function sendData(event:MouseEvent) : void {
      // i guess here is the problem (tbName.text is UTF-16)
      variables.name = tbName.text;
  
      varLoader.load(varSend);
  }
  </code></pre>
  
  <p>Is there any way to send the data so that PHP script gets the data in UTF-8 format?</p>
  
  <p>(PHP script is retrieving the value using the $_POST['name']).</p>
  
  <hr>
  
  <p><strong>EDIT</strong> (after useful comments): </p>
  
  <p>I've tried to convert the POST variable to UTF-8 by using iconv() but I get only question marks. That may mean that I was wrong in assuming the php got the string in a UTF-16 format. It seems not. But now I have absolutely no idea how to fix this.</p>
  
  <p>The characters in question are croatian characters (č, ć, š, ž and đ), all are in Windows-1250 encoding. If I manually edit the entry in phpMyAdmin and enter any of those characters, everything works great. But if I am doing it thru flash, it doesn't work.</p>
  
  <p>Another strange thing, I have removed iconv and put everything like it was in the beginning and now only non-special characters get shown up to first croatian. For example, if I write "ačasdfadfa", only the "a" gets stored int the database.</p>
  
  <hr>
  
  <p><strong>Another edit:</strong></p>
  
  <p>I have now tried to switch the croatian characters into something ASCII (see the code below) and then return them to č, ć, etc. on the PHP side. Flash obviously forwards this right (since there's no special characters anymore), but the PHP does not correctly convert the chars back to the string. This is what I was doing.</p>
  
  <p><a href="http://pastebin.com/qjVcrNuV" rel="nofollow noreferrer">http://pastebin.com/qjVcrNuV</a></p>
  
  <p>so I guess it's something with PHP or how it stores the data into the database. The PHP file itself is UTF-8 encoded.</p>