通过api程序得到xml的$ret内容为
<?xml version="1.0" encoding="gb2312" ?>
<property>
<returncode><![CDATA[200]]></returncode>
<domain><![CDATA[pla309.com]]></domain>
<sucdate><![CDATA[2011-12-10 00:00:00]]></sucdate>
<deaddate><![CDATA[2012-12-10 00:00:00]]></deaddate>
<domainpwd><![CDATA[password123]]></domainpwd>
<dns1><![CDATA[dns20.hichina.com]]></dns1>
<dns2><![CDATA[dns21.hichina.com]]></dns2>
<address_en><![CDATA[Hutong, Dongcheng District, Maple Garden B2106 positions linedzc]]></address_en>
<firstname><![CDATA[fangzc]]></firstname>
<lastname><![CDATA[li rongzc]]></lastname>
<organization_en><![CDATA[fang li rong]]></organization_en>
<city><![CDATA[beijingzc]]></city>
<state><![CDATA[beijingzc]]></state>
<address_zh><![CDATA[北京市东城区]]></address_zh>
<name><![CDATA[方丽荣zc]]></name>
<organization_zh><![CDATA[方丽荣]]></organization_zh>
<ccity><![CDATA[北京zc]]></ccity>
<cstate><![CDATA[北京zc]]></cstate>
<manager><![CDATA[]]></manager>
<organization_type><![CDATA[]]></organization_type>
<postcode><![CDATA[100001]]></postcode>
<country><![CDATA[中国]]></country>
<phone><![CDATA[86-01052476850-1]]></phone>
<fax><![CDATA[86-01052476850-1]]></fax>
<email><![CDATA[[email protected]]]></email>
<admin_same_as><![CDATA[0]]></admin_same_as>
<a_address_en><![CDATA[Hutong, Dongcheng District, Maple Garden B2106 positions linedg]]></a_address_en>
<a_firstname><![CDATA[fangg]]></a_firstname>
<a_lastname><![CDATA[li rongg]]></a_lastname>
<a_organization_en><![CDATA[fang li rongg]]></a_organization_en>
<a_city><![CDATA[beijingg]]></a_city>
<a_state><![CDATA[beijingg]]></a_state>
<a_address_zh><![CDATA[北京东城区g]]></a_address_zh>
<a_name><![CDATA[方丽荣g]]></a_name>
<a_organization_zh><![CDATA[北京科恩管理有限公司g]]></a_organization_zh>
<a_ccity><![CDATA[北京g]]></a_ccity>
<a_cstate><![CDATA[北京g]]></a_cstate>
<a_postcode><![CDATA[100002]]></a_postcode>
<a_country><![CDATA[中国]]></a_country>
<a_phone><![CDATA[86-01052476850-2]]></a_phone>
<a_fax><![CDATA[86-01052476850-2]]></a_fax>
<a_email><![CDATA[[email protected]]]></a_email>
<tech_same_as><![CDATA[0]]></tech_same_as>
<t_address_en><![CDATA[Hutong, Dongcheng District, Maple Garden B2106 positions linedjs]]></t_address_en>
<t_firstname><![CDATA[fangjs]]></t_firstname>
<t_lastname><![CDATA[li rongjs]]></t_lastname>
<t_organization_en><![CDATA[fang li rongjs]]></t_organization_en>
<t_city><![CDATA[beijingjs]]></t_city>
<t_state><![CDATA[beijingjs]]></t_state>
<t_address_zh><![CDATA[北京东城区js]]></t_address_zh>
<t_name><![CDATA[方丽荣js]]></t_name>
<t_organization_zh><![CDATA[北京科恩管理有限公司js]]></t_organization_zh>
<t_ccity><![CDATA[北京js]]></t_ccity>
<t_cstate><![CDATA[北京js]]></t_cstate>
<t_postcode><![CDATA[100004]]></t_postcode>
<t_country><![CDATA[中国]]></t_country>
<t_phone><![CDATA[86-01052476850-4]]></t_phone>
<t_fax><![CDATA[86-01052476850-4]]></t_fax>
<t_email><![CDATA[[email protected]]]></t_email>
<bill_same_as><![CDATA[0]]></bill_same_as>
<b_address_en><![CDATA[Hutong, Dongcheng District, Maple Garden B2106 positions linedjf]]></b_address_en>
<b_firstname><![CDATA[fangjf]]></b_firstname>
<b_lastname><![CDATA[li rongjf]]></b_lastname>
<b_organization_en><![CDATA[fang li rongjf]]></b_organization_en>
<b_city><![CDATA[beijingjf]]></b_city>
<b_state><![CDATA[beijingjf]]></b_state>
<b_address_zh><![CDATA[北京东城区jf]]></b_address_zh>
<b_name><![CDATA[方丽荣jf]]></b_name>
<b_organization_zh><![CDATA[北京科恩管理有限公司jf]]></b_organization_zh>
<b_ccity><![CDATA[北京jf]]></b_ccity>
<b_cstate><![CDATA[北京jf]]></b_cstate>
<b_postcode><![CDATA[100003]]></b_postcode>
<b_country><![CDATA[中国]]></b_country>
<b_phone><![CDATA[86-01052476850-3]]></b_phone>
<b_fax><![CDATA[86-01052476850-3]]></b_fax>
<b_email><![CDATA[[email protected]]]></b_email>
</property>api程序为<?php //要post的数据
$argv = $_POST;

echo PostData($argv, "8783458", "[email protected]","toiqoiu");


/*
$arg,$userid,$email,$password 分别表示:
用户post的数据,您的id,您的email,您的密码
*/
function PostData($arg,$userid,$email,$password) 
{
//构造要post的字符串 
$params ="";
foreach ($arg as $key=>$value) { 
$params.= "&".$key."="; $params.= urlencode($value); 

$params = substr($params,1);
$params.="&userid=".$userid;
$sVTime =date("YmdHi",time());
$params.="&vtime=".$sVTime;
$params.="&userstr=".md5($userid.$password.$email.$sVTime);

    $length = strlen($params);
    
    //以下参数请按万网最终 API 发布地址进行修改
    $apiHost = "api.hichina.com";
    $apiPort = 80;
    $apiUrl = "/wwwnetcn.aspx";
    
    $fp = fsockopen($apiHost,$apiPort,$errno,$errstr,10) or exit($errstr."--->".$errno); 
    
    //构造post请求的头 
    $header = "POST ". $apiUrl . " HTTP/1.1\r\n";
    $header .= "Host:" . $apiHost . "\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
    $header .= "Content-Length: ".$length."\r\n"; 
    $header .= "Connection: Close\r\n\r\n";
    //添加post的字符串 
    $header .= $params."\r\n"; 
    //发送post的数据 
    fputs($fp,$header); 
    $inheader = 1; 
$ret="";
    while (!feof($fp)) {
        $line = fgets($fp,1024); //去除请求包的头只显示页面的返回数据 
        if ($inheader && ($line == "\n" || $line == "\r\n")) {
             $inheader = 0; 
        } 
        if ($inheader == 0) { 
            $ret.=$line; 
        } 
    } 
fclose($fp); 
//return $ret;
//分析XML
}
?>

解决方案 »

  1.   

    $xml = simplexml_load_string($string, 'SimpleXMLElement', LIBXML_NOCDATA);
    print_r((string)$xml->b_email );
      

  2.   

    老大这个不行啊。出现错误提示:
    Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 2: parser error : XML declaration allowed only at the start of the document in /data/home/hmu084105/htdocs/postapi.php on line 66Warning: simplexml_load_string() [function.simplexml-load-string]: <?xml version="1.0" encoding="gb2312" ?> in /data/home/hmu084105/htdocs/postapi.php on line 66Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /data/home/hmu084105/htdocs/postapi.php on line 66Warning: simplexml_load_string() [function.simplexml-load-string]: Entity: line 17: parser error : Input is not proper UTF-8, indicate encoding ! Bytes: 0xB1 0xB1 0xBE 0xA9 in /data/home/hmu084105/htdocs/postapi.php on line 66Warning: simplexml_load_string() [function.simplexml-load-string]: <address_zh><![CDATA[北京市东城区]]></address_zh> in /data/home/hmu084105/htdocs/postapi.php on line 66Warning: simplexml_load_string() [function.simplexml-load-string]: ^ in /data/home/hmu084105/htdocs/postapi.php on line 66