1 <?php 2 3 $soap=new SoapServer(null,array('uri'=>"http://localhost:7000/serverSoap.php")); 4 $soap->addFunction('Select'); 5 $soap->addFunction(SOAP_FUNCTION_ALL); 6 $soap->handle(); 7 8 function Select() 9 { 10 $con=mysql_connect("localhost","root",""); 11 mysql_query("SET CHARACTER SET utf8"); 12 if(!$con) 13 { 14 die('could not connect:' . mysql_error()); 15 } 16 mysql_select_db("world",$con); 17 $result=mysql_query("select * from worldcup where kind=1"); 18 $arr=array(); 19 while($row=mysql_fetch_array($result)) 20 { 21 $tmp=array('id'=>$row['_id'],'team1'=>$row['team1'],'team2'=>$row['team2'],'score'=>$row["score"]); 22 array_push($arr,$tmp); 23 } 24 mysql_close($con); 25 return json_encode($arr); 26 } 27 28 ?> 29 30 31 32 <?php 33 mysql_query("SET CHARACTER SET utf8"); 34 $client=new SoapClient(null,array('location'=>"http://localhost:7000/serverSoap.php",'uri'=>"http://localhost:7000/")); 35 $str= $client->Select(); 36 $str= preg_replace("#\u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '\1'))", $str); 37 echo $str; 38 ?>
上面是服务器端,下面是客户端