Home >Backend Development >PHP Tutorial >请问这个xml怎么用simplexml解析,vardump总是false
版主,又来求助了。。。这回事是网页返回的XML数据,我不知道为什么不能用simplexml读取,var_dump显示false
echo '#########################'.'</br></br>'; var_dump($xml); echo '#########################'; echo '<br>'.'<br>'.'<br>'.$xml->xsm->nickname;
echo '#########################'.'</br></br>'; var_dump(simplexml_load_string($xml); echo '#########################'; echo '<br>'.'<br>'.'<br>'.$xml->xsm->nickname;
$xml = preg_replace('/!|--/', '', $xml);var_dump(simplexml_load_string($xml));
$xml = preg_replace('/!|--/', '', $xml);var_dump(simplexml_load_string($xml));
//$xml='<!--?xml version="1.0" encoding="gbk"?-->'; $xml = preg_replace('/!--\?|--/','', $xml); var_dump($xml);
你为什么要自作聪明呢
$xml = preg_replace('/!|--/', '', $xml);var_dump(simplexml_load_string($xml));
$xml = '<xml version="1.0" encoding="gbk"?>'.$xml; var_dump(simplexml_load_string($xml));
还是那话,你为什么要自作聪明呢
你为什么要自作聪明呢
那是因为你不给我你的数据
还是那话,你为什么要自作聪明呢
你光截图是没有用的!
你怎么知道其中没有不可打印的字符呢?
那是因为你不给我你的数据
<?xml version="1.0" encoding="gbk"?><xsm code="0000" msg="验证成功abc" trans_time="20140808162708"><userId>114</userId><nickName>wedc</nickName><userType>2</userType><comId>116</comId><saledptId>11601</saledptId><refId>1062014</refId><comName></comName><domainUrl>v=2014080600</domainUrl><comType>02</comType><comShort></comShort><parentComId>11620001</parentComId><expirationTime>1407488228735</expirationTime><planText>10116226011162288228735</planText><signatureValue>c6959b4eacf7b2f</signatureValue></xsm>
你光截图是没有用的!
你怎么知道其中没有不可打印的字符呢?
SimpleXMLElement Object( [@attributes] => Array ( [code] => 0000 [msg] => 验证成功abc [trans_time] => 20140808162708 ) [userId] => 114 [nickName] => wedc [userType] => 2 [comId] => 116 [saledptId] => 11601 [refId] => 1062014 [comName] => SimpleXMLElement Object ( ) [domainUrl] => v=2014080600 [comType] => 02 [comShort] => SimpleXMLElement Object ( ) [parentComId] => 11620001 [expirationTime] => 1407488228735 [planText] => 10116226011162288228735 [signatureValue] => c6959b4eacf7b2f)这不是可以吗?
你光截图是没有用的!
你怎么知道其中没有不可打印的字符呢?
SimpleXMLElement Object( [@attributes] => Array ( [code] => 0000 [msg] => 验证成功abc [trans_time] => 20140808162708 ) [userId] => 114 [nickName] => wedc [userType] => 2 [comId] => 116 [saledptId] => 11601 [refId] => 1062014 [comName] => SimpleXMLElement Object ( ) [domainUrl] => v=2014080600 [comType] => 02 [comShort] => SimpleXMLElement Object ( ) [parentComId] => 11620001 [expirationTime] => 1407488228735 [planText] => 10116226011162288228735 [signatureValue] => c6959b4eacf7b2f)这不是可以吗?
SimpleXMLElement Object( [@attributes] => Array ( [code] => 0000 [msg] => 验证成功abc [trans_time] => 20140808162708 ) [userId] => 114 [nickName] => wedc [userType] => 2 [comId] => 116 [saledptId] => 11601 [refId] => 1062014 [comName] => SimpleXMLElement Object ( ) [domainUrl] => v=2014080600 [comType] => 02 [comShort] => SimpleXMLElement Object ( ) [parentComId] => 11620001 [expirationTime] => 1407488228735 [planText] => 10116226011162288228735 [signatureValue] => c6959b4eacf7b2f)这不是可以吗?