I’m far from an expert in PHP and I’m struggling to resolve an issue that I’m having here.
What I’m doing is pulling core information from this URL:
http://us.battle.net/wow/en/arena/kelthuzad/3v3/W%C3%BCstenfuchs%20zu%20gro%C3%9F/
In AS3 this provides me with the following, from the team name:
http://us.battle.net/wow/en/arena/kelthuzad/3v3/W%C3%BCstenfuchs%20zu%20gro%C3%9F/
Now, this is fine. If I decodeURI it, it gives me:
http://us.battle.net/wow/en/arena/kelthuzad/3v3/Wüstenfuchs zu groß/
My issue comes when I’m sending the information from AS3 to PHP. I’m doing it with encoding intact, however no matter what I try PHP is reading the code incorrectly. This is the output:
var9=http://us.battle.net/wow/en/arena/kelthuzad/3v3/Wüstenfuchs zu groÃ/
Even when I try to decode this, it gives the exact same output. If I send it from AS3 to PHP already decoded, it again gives the same result as above.
My code for AS3 is:
var phpVars:URLVariables = new URLVariables();
phpVars.team = _team;
urlRequest.method = URLRequestMethod.POST;
urlRequest.data = phpVars;
urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
urlLoader.addEventListener(Event.COMPLETE, returnResult);
urlLoader.load(urlRequest);
My code for PHP is:
header("Content-type: text/html; charset=utf-8");
function updateData(){
$team2 = mysql_real_escape_string($_POST['team']);
echo("var9=".$team2);
$sql = "INSERT INTO title_test SET field1='$team2'";
mysql_query($sql);
}
This puts into the database:
http://us.battle.net/wow/en/arena/kelthuzad/3v3/Wüstenfuchs zu groß/
It’s also worth noting that I’m trying to do a query with the $team2 data within PHP that is also failing, as it is not encoding correctly.
What step am I missing here?
Edit: utf-8 is enabled on the DB.
Okay, after much heartache and many headaches, I have now got this to work… However the method that makes it work seems very strange and not best practise.
AS3 is now:
PHP is now:
Connect.php is now
This now correctly returns information into the database and allows the URL queries to work. The echo’d information back into Flash still shows incorrectly, though.
I’ll leave this open, as I’m certain that this method is incorrect. I’m almost certain that you should leave it encoded going out of AS3 and unencode it in PHP.