views:

358

answers:

5

Hi Everyone,

I'm calling a php file from Flash and adding variables afterwards like so: http://www.randomwebsite.com/something.php?title=爸爸

It works fine if I copy and paste this directly into the web browser, however if I call it through flash, the address bar would end up like this: something.php?title=??

Is there anything I can do from PHP or flash to encode/decode the string? Any help is greatly appreciated.

Thanks, Will

EDIT: Thanks guys, that method worked perfectly. Everything is echoing out fine, however I'm now having some issues inserting the information into my database via MySQL, all of my fields are set to UTF-8. I'm getting some weird characters instead of the Chinese characters.

Many thanks, Will

+3  A: 

You need to URL-encode parameters you put in the query string. Whilst IRIs can contain a literal , URIs can't. It should be encoded as %E7%88%B8. (It will generally still appear as in the address bar, except in some cases in IE.)

encodeURIComponent() is the function to do this in JavaScript/ActionScript.

bobince
A: 

See rfc1738 2.2 (http://www.faqs.org/rfcs/rfc1738), you need to encode your string. I don't know how to do this in Flash, but PHP provides you with the functions (raw-)urlencode() and (raw-)urldecode() to do this.

svens
A: 

You need to URL-encode the characters (the browser you're using probably does this for you automatically). This is used to allow transmission of characters that are not normally allowed in URLs (like spaces) or have special meaning (like '?' and '&').

Because the characters you're using are not standard ASCII, they should be encoded as Unicode. This is done automatically for you when you call the top-level encodeURIComponent() function in Flash, and results in several %xx characters per Unicode character put in.

Cameron
A: 

There is actually a couple of url-encoding/decoding functions available (in as3). Each differ a little from the other.

Check these out:

above is from the flex reference, I assume they will be available in CS as well.

andkrup
+1  A: 

If you are having problems inserting into the database you need to make sure that everything involved in the process is utf8. If you have tested your query in phpmyadmin and it works fine I would suggest adding the following above your query in your php script:

mysql_query("SET character_set_client=utf8", $connection);
mysql_query("SET character_set_connection=utf8", $connection);
Drew