Web 服务 unicode 字符显示为问号
我使用 nusoap 和客户端脚本编写了 php Web 服务。当我通过 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 ) )
I wrote php web service using nusoap and client script. When I fetch the database records via php client unicode records are displaying as ?????????? ???? ????
("questions marks").
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>
output
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 ) )
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
而不是
对我有用。
Using
instead of
worked for me.
在 server.php 文件中使用:
代替
: 可以解决问题。
Using:
instead:
in server.php file, will solve the problem.