调用PHP脚本使用UTF-8 POST变量 [英] Calling Php Script with UTF-8 POST variables

查看:140
本文介绍了调用PHP脚本使用UTF-8 POST变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

AS3文档说字符串在AS3是UTF-16格式。

AS3 documentation says that Strings in AS3 are in UTF-16 format.

有一个暴扣,其中用户可以输入一些数据的文本框。

There is a textbox on a Flash Clip where user can type some data.

当点击一个按钮,我想这个数据被发送到一个PHP脚本。

When a button is clicked, I want this data to be sent to a php script.

我把一切都成立,但似乎在PHP脚本获取的数据中UTF-16格式。在数据库中的数据(这是utf-8)显示了一些不可辨认的字符(这里特殊字符被使用),这意味着数据尚未发送在一个正确的编码。

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.

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);

被点击提交按钮,以下处理被执行。

When submit button is clicked, the following handler gets executed.

function sendData(event:MouseEvent) : void {
    // i guess here is the problem (tbName.text is UTF-16)
    variables.name = tbName.text;

    varLoader.load(varSend);
}

有没有什么办法来发送数据,使PHP脚本获取数据以UTF-8格式?

Is there any way to send the data so that PHP script gets the data in UTF-8 format?

(PHP脚本使用检索值$ _ POST ['名称'])。

(PHP script is retrieving the value using the $_POST['name']).

修改(以后有用的意见):

EDIT (after useful comments):

我试图用的iconv()的POST变量转换为UTF-8,但我得到的只有问号。这可能意味着,我错在假设了PHP在字符串中的UTF-16格式。这似乎并非如此。但现在我完全不知道如何解决这个问题。

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.

有问题的字符是克罗地亚的字符(C,C,S,Z和DJ),都是在Windows-1250编码。如果我手动编辑在phpMyAdmin的条目并输入任何这些字符,一切都很正常。但是,如果我这样做通闪光灯,这是行不通的。

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.

另一个奇怪的事情,我已删除的iconv,把一切就像是在开始的时候,现在唯一的非特殊字符得到显示为先在克罗地亚。举例来说,如果我写的ačasdfadfa,只有一获取存储INT数据库。

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.

另一个编辑:

我现在已经尝试克罗地亚字符转换成ASCII码的东西(见$ C $低于C),然后将它们返还给C,C等,在PHP端。闪光灯显然转发这一权利(因为没有特殊字符了),但PHP不正确地转换字符后面的字符串。这是我在做什么。

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.

http://pastebin.com/qjVcrNuV

所以我想这件事情用PHP或者它如何存储数据到数据库中。该PHP文件本身是UTF-8 EN codeD。

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.

推荐答案

更新:

如果它确实是UTF-16的数据,你从Flash获得,你可以作为一个快速修复尝试在PHP转换输入:

If it's indeed UTF-16 data you are getting from Flash, you could as a quick fix try converting the input in PHP:

$name = iconv("UTF-16", "UTF-8", $_POST["name"]); 

您可以尝试,并检查是否有数据没问题即可。 但是,如果可能的话,我会说这将是preferable来下载Flash发送UTF-8的数据。

you could try that and check whether the data looks okay then. however, if at all possible, I would say it would be preferable to get Flash to send UTF-8 data.

旧的回答:

<炒>

这听起来并不像UTF-16给我,但显示在一个ISO-8859-1 EN codeD环境更像是UTF-8的数据。你在哪里输出变量?是你正在做的的输出连接codeD的UTF-8,以及网页? (请参阅浏览器的编码菜单)如果让我打赌,我会说闪存被正确传送它们为UTF-8,但问题是在 输出端。

This doesn't sound like UTF-16 to me but more like UTF-8 data being displayed in an ISO-8859-1 encoded environment. Where are you outputting the variables? Is the page you are doing the output on encoded in UTF-8 as well? (See the browser's "encoding" menu) If I had to bet, I would say Flash is transmitting them correctly as UTF-8, but the problem is on the output end.

< /投机>

这篇关于调用PHP脚本使用UTF-8 POST变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆