Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 用XML-RPC和MySQL处理汉字_Php_Character Encoding_Xml Rpc_Cjk - Fatal编程技术网

Php 用XML-RPC和MySQL处理汉字

Php 用XML-RPC和MySQL处理汉字,php,character-encoding,xml-rpc,cjk,Php,Character Encoding,Xml Rpc,Cjk,我有一个异步web服务,其中移动应用程序的用户可以在手机上发布评论,它使用JSON将帖子上传到API,服务器将帖子输入数据库,并将确认信息发送回设备。服务器使用XML-RPC传递消息,但与设备的所有通信都由JSON完成 我现在正在尝试添加对汉字的支持。当我从设备发送帖子时,JSON文本在发送时是这样的: Request object: ( { comment = "\U4e2d\U56fd"; "post_id" = 119791544; } )

我有一个异步web服务,其中移动应用程序的用户可以在手机上发布评论,它使用JSON将帖子上传到API,服务器将帖子输入数据库,并将确认信息发送回设备。服务器使用XML-RPC传递消息,但与设备的所有通信都由JSON完成

我现在正在尝试添加对汉字的支持。当我从设备发送帖子时,JSON文本在发送时是这样的:

Request object:

(
    {
        comment = "\U4e2d\U56fd";
        "post_id" = 119791544;
    }
)
该注释值表示两个汉字中国. 当它被输入数据库时,它显示为??。查看十六进制值,这将转换为3F3F,因此数据库肯定只是存储问号,而不是在显示字符时遇到问题。这也意味着服务器知道只有两个字符通过,所以它可以识别输入的字符大小。这是服务器从设备接收数据时调用的函数:

function server_impl_post_comment($m)
{
    global $xmlrpcerruser;

    $auth = server_utils_authenticate_client();

    // return error if client is not authorised to use the api
    if (!$auth['result'])
    {
        return new xmlrpcresp(0, $xmlrpcerruser, $auth['reason']);
    }

    logger_api_log_method_call('ff.post_comment', $auth['user_id']);

    $args   = $m->getParam( 0 );

    $c['user_id'] = $auth['user_id'];
    $c['post_id'] = $args->structmem( "post_id" )->scalarval();
    $c['comment'] = $args->structmem( "comment" )->scalarval();

    // @todo: chinese characters come through as ? here

    // submit the comment
    $comment = post_comment($c);
    $post = post_get_post($c['post_id']);

    $result = server_utils_format_result_struct(TRUE, POST_COMMENT_TITLE, POST_COMMENT_MSG, POST_COMMENT_BUTTON, POST_COMMENT_SHOW, $c['post_id'], $comment);
    $result['post_info'] = server_utils_format_post_info($post);
    $result['post_up_votes'] = $post['post_vote_up_count'];
    $result['post_down_votes'] = $post['post_vote_down_count'];
    $result['post_comments'] = $post['post_comment_count'];

    return new xmlrpcresp(php_xmlrpc_encode($result));
}

在@todo注释行,我添加了一个日志记录方法,$c['comment']作为??再一次一开始我试着记录$m的价值,但由于某种原因,这不起作用。服务器上使用的XML-RPC库是由Edd Dumbill编写的xmlrpc.inc v1.169,据我所知,它支持UTF-8。你知道这是怎么回事吗?我已经能够使用SQL将汉字直接插入数据库,因此它一定是在进入数据库的过程中发生的。

您的MySQL连接和表字段排序规则都必须支持汉字。UTF unicode连接是一个很好的选择


例如,调用mysql\u set\u charsetutf8,$link,在调用mysql\u connect之后立即将连接设置为UTF8

感谢您的提示,尽管所有MySQL内容都在post_comment函数中,因此不会影响$c['comment']的值-因此错误必须在这之前。哦,那么XML-RPC的post communication的字符集设置正确吗?如果我是对的,发布到数据库的内容已经被篡改了。您可以将内容记录在放置@todo的位置,以查看内容是否正确地传递到脚本中。如果记录的内容是正确的,那么您的数据库连接是错误的。我在@todo的位置放置了一个日志函数,它只记录了两个问号,因此在此之前一定发生了一些事情。这可能与实际PHP文件的编码有关吗?这可能是问题所在,是的,但在阅读了phpxmlrpc文档之后,我认为问题可能与scalarval方法处理xmlrpcval对象中字符串的方式有关。如果发送的数据确实正确,我建议您检查库的代码,或者联系Edd Dumbill本人。