Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web service unicode characters display as question marks

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 ) )
like image 723
Roshan Wijesena Avatar asked Apr 21 '11 11:04

Roshan Wijesena


2 Answers

Using

$client->decode_utf8 = false;

instead of

$client->decode_utf8 = true;

worked for me.

like image 102
Sabo Avatar answered Oct 18 '22 04:10

Sabo


Using:

$server->soap_defencoding = 'UTF-8';
$server->decode_utf8 = false;
$server->encode_utf8 = true;

instead:

$server->soap_defencoding = 'UTF-8';
$server->decode_utf8 = true;

in server.php file, will solve the problem.

like image 1
Ljupco Sofijanov Avatar answered Oct 18 '22 02:10

Ljupco Sofijanov