草庐IT

php - Web 服务 unicode 字符显示为问号

coder 2023-10-03 原文

我使用 nusoap 和客户端脚本编写了 php 网络服务。当我通过 php 客户端获取数据库记录时,unicode 记录显示为 ?????????? ??? ????(“问号”)。

server.php

<?php

    //call library
    require_once 'config.php';
    include_once("nusoap/lib/nusoap.php");

    $conn = new Dbconn(HOST, DB, USER, PASS);

    //using soap_server to create server object
    $server = new soap_server;


    $server->soap_defencoding = 'UTF-8';
    $server->decode_utf8 = true;
    //register a function that works on server

    $server->configureWSDL('designationdivisionwsdl', 'urn:designationdivisionwsdl');
    // Register the method to expose
    //$server->register('getallbook',                // method name
    //    array('name' => 'xsd:string'),        // input parameters
    //    array('return' => 'xsd:string'),      // output parameters
    //    'urn:hellowsdl',                      // namespace
    //    'urn:hellowsdl#hello',                // soapaction
    //    'rpc',                                // style
    //    'encoded',                            // use
    //    'Says hello to the caller'            // documentation
    //);
    //
    //
    //Definimos la estructura de cada registro
    $server->wsdl->addComplexType(
            'designations',
            'complexType',
            'struct',
            'all',
            '',
            array(
                'jobtit_name' => array('name' => 'jobtit_name', 'type' => 'xsd:string'),
                'jobtit_name_si' => array('name' => 'jobtit_name_si', 'type' => 'xsd:string'),
                'jobtit_name_ta' => array('name' => 'jobtit_name_ta', 'type' => 'xsd:string')
            )
    );

    $server->wsdl->addComplexType('estructura', 'complexType', 'array', '',
            'SOAP-ENC:Array', array(),
            array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:designations[]')),
            'tns:designations');

    $server->register('getDesignations', array(), array('return' => 'tns:estructura'));

    // create the function

    function getDesignations() {

        $ssql_ = mysql_query("select jobtit_name, jobtit_name_si, jobtit_name_ta from hs_hr_job_title") or die(mysql_error());
        $numrows = mysql_num_rows($ssql_);
        $designationList = array();
        for ($x = 0; $x < $numrows; $x++) {
            $designationList[] = mysql_fetch_array($ssql_);
        }
        return $designationList;
    }

    //start getDivisionlist webMethod

    $server->wsdl->addComplexType(
            'divisions',
            'complexType',
            'struct',
            'all',
            '',
            array(
                'comp_code' => array('comp_code' => 'comp_code', 'type' => 'xsd:string'),
                'title' => array('title' => 'title', 'type' => 'xsd:string'),
                'title_si' => array('title_si' => 'title_si', 'type' => 'xsd:string'),
                'title_ta' => array('title_ta' => 'title_ta', 'type' => 'xsd:string'),
            )
    );

    $server->wsdl->addComplexType('divisiontype', 'complexType', 'array', '',
            'SOAP-ENC:Array', array(),
            array(array('ref' => 'SOAP-ENC:arrayType', 'wsdl:arrayType' => 'tns:divisions[]')),
            'tns:divisions');

    $server->register('getDivisions', array(), array('return' => 'tns:divisiontype'));

    function getDivisions() {

        $ssql_ = mysql_query("select title, title_si, title_ta from  hs_hr_compstructtree") or die(mysql_error());
        $numrows = mysql_num_rows($ssql_);
        $divisionList = array();
        for ($x = 0; $x < $numrows; $x++) {
            $divisionList[] = mysql_fetch_array($ssql_);
        }
        return $divisionList;
    }

    // create HTTP listener
    $server->service($HTTP_RAW_POST_DATA);

    exit();
?>

client.php

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<body>
<?php
include_once("nusoap/lib/nusoap.php");
ini_set ('soap.wsdl_cache_enabled', 0);

$client = new nusoap_client('http://localhost/esamwebservice/server.php?wsdl');

//$response = $client->call('getDesignations');
$client->soap_defencoding = 'UTF-8';
$client->decode_utf8 = true;
$response = $client->call('getDivisions');
print_r($response);die;


?>
</body>
</html>

输出

Array ( [0] => Array ( [title] => The Government of Sri Lanka [title_si] => ????? ???? ???????????????? ???????? ????? [title_ta] => ?????? ?????? ??????? ???????? ) [1] => Array ( [title] => IT Department ) [2] => Array ( [title] => PHP [title_si] => PHP_si [title_ta] => ???? ? ?? ? ) [3] => Array ( [title] => Land Section [title_si] => ???? ????? [title_ta] => ??? ? ? ) [4] => Array ( [title] => sdfsdf [title_si] => dsafsda [title_ta] => fasdfasdghd ) [5] => Array ( [title] => dfsdfdf ) [6] => Array ( [title] => dsfsdfdsf ) [7] => Array ( [title] => sdfsdfsd [title_si] => ???? ????? ) [8] => Array ( [title] => IT Department two [title_si] => dfgfd [title_ta] => gdfgfd ) [9] => Array ( [title] => fg ) [10] => Array ( [title] => Western Province [title_si] => Western Province_si [title_ta] => Western Province_ta ) [11] => Array ( [title] => 456 ) [12] => Array ( [title] => Test ) [13] => Array ( [title] => asdasd ) [14] => Array ( [title] => asd ) [15] => Array ( [title] => fsdfsd ) [16] => Array ( [title] => sdfsdf [title_si] => sdfsd [title_ta] => fsdf ) )

最佳答案

使用

$client->decode_utf8 = false;

代替

$client->decode_utf8 = true;

为我工作。

关于php - Web 服务 unicode 字符显示为问号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5743528/

有关php - Web 服务 unicode 字符显示为问号的更多相关文章

  1. ruby - 如何从 ruby​​ 中的字符串运行任意对象方法? - 2

    总的来说,我对ruby​​还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用

  2. Ruby 解析字符串 - 2

    我有一个字符串input="maybe(thisis|thatwas)some((nice|ugly)(day|night)|(strange(weather|time)))"Ruby中解析该字符串的最佳方法是什么?我的意思是脚本应该能够像这样构建句子:maybethisissomeuglynightmaybethatwassomenicenightmaybethiswassomestrangetime等等,你明白了......我应该一个字符一个字符地读取字符串并构建一个带有堆栈的状态机来存储括号值以供以后计算,还是有更好的方法?也许为此目的准备了一个开箱即用的库?

  3. ruby-on-rails - 在 Rails 中将文件大小字符串转换为等效千字节 - 2

    我的目标是转换表单输入,例如“100兆字节”或“1GB”,并将其转换为我可以存储在数据库中的文件大小(以千字节为单位)。目前,我有这个:defquota_convert@regex=/([0-9]+)(.*)s/@sizes=%w{kilobytemegabytegigabyte}m=self.quota.match(@regex)if@sizes.include?m[2]eval("self.quota=#{m[1]}.#{m[2]}")endend这有效,但前提是输入是倍数(“gigabytes”,而不是“gigabyte”)并且由于使用了eval看起来疯狂不安全。所以,功能正常,

  4. ruby - 使用 ruby​​ 和 savon 的 SOAP 服务 - 2

    我正在尝试使用ruby​​和Savon来使用网络服务。测试服务为http://www.webservicex.net/WS/WSDetails.aspx?WSID=9&CATID=2require'rubygems'require'savon'client=Savon::Client.new"http://www.webservicex.net/stockquote.asmx?WSDL"client.get_quotedo|soap|soap.body={:symbol=>"AAPL"}end返回SOAP异常。检查soap信封,在我看来soap请求没有正确的命名空间。任何人都可以建议我

  5. ruby-on-rails - unicode 字符串的长度 - 2

    在我的Rails(2.3,Ruby1.8.7)应用程序中,我需要将字符串截断到一定长度。该字符串是unicode,在控制台中运行测试时,例如'א'.length,我意识到返回了双倍长度。我想要一个与编码无关的长度,以便对unicode字符串或latin1编码字符串进行相同的截断。我已经了解了Ruby的大部分unicode资料,但仍然有些一头雾水。应该如何解决这个问题? 最佳答案 Rails有一个返回多字节字符的mb_chars方法。试试unicode_string.mb_chars.slice(0,50)

  6. ruby - 具有身份验证的私有(private) Ruby Gem 服务器 - 2

    我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..

  7. ruby - 将差异补丁应用于字符串/文件 - 2

    对于具有离线功能的智能手机应用程序,我正在为Xml文件创建单向文本同步。我希望我的服务器将增量/差异(例如GNU差异补丁)发送到目标设备。这是计划:Time=0Server:hasversion_1ofXmlfile(~800kiB)Client:hasversion_1ofXmlfile(~800kiB)Time=1Server:hasversion_1andversion_2ofXmlfile(each~800kiB)computesdeltaoftheseversions(=patch)(~10kiB)sendspatchtoClient(~10kiBtransferred)Cl

  8. ruby-on-rails - Rails 编辑表单不显示嵌套项 - 2

    我得到了一个包含嵌套链接的表单。编辑时链接字段为空的问题。这是我的表格:Editingkategori{:action=>'update',:id=>@konkurrancer.id})do|f|%>'Trackingurl',:style=>'width:500;'%>'Editkonkurrence'%>|我的konkurrencer模型:has_one:link我的链接模型:classLink我的konkurrancer编辑操作:defedit@konkurrancer=Konkurrancer.find(params[:id])@konkurrancer.link_attrib

  9. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  10. ruby - 如何以所有可能的方式将字符串拆分为长度最多为 3 的连续子字符串? - 2

    我试图获取一个长度在1到10之间的字符串,并输出将字符串分解为大小为1、2或3的连续子字符串的所有可能方式。例如:输入:123456将整数分割成单个字符,然后继续查找组合。该代码将返回以下所有数组。[1,2,3,4,5,6][12,3,4,5,6][1,23,4,5,6][1,2,34,5,6][1,2,3,45,6][1,2,3,4,56][12,34,5,6][12,3,45,6][12,3,4,56][1,23,45,6][1,2,34,56][1,23,4,56][12,34,56][123,4,5,6][1,234,5,6][1,2,345,6][1,2,3,456][123

随机推荐