使用 simplexml_load_string 求解 simplexml_load_string()
Solve simplexml_load_string() using simplexml_load_string
经过多次尝试仍然没有成功,尝试访问这个'http://www.autobid.co.za/halfway/vehicledetails.php?wsdl,提供用户名和密码,然后收集xml 反馈。此代码:
$client = new SoapClient('http://www.autobid.co.za/halfway/vehicledetails.php?wsdl');
$result = $client->getVehicleDetails('spwf87','hk8*9jd');
echo('<pre>'.$result.'</pre>');
转储整个文本字段,当然希望按照页面源代码对其进行清理:
<pre><![CDATA[<VEHICLEDETAILS><VEHICLE><ID....
等,所以尝试使用:
$client = new SoapClient('http://www.autobid.co.za/halfway/vehicledetails.php?wsdl');
$result = $client->getVehicleDetails('pass','user');
$content = simplexml_load_string($result, null,LIBXML_NOCDATA);
$content = simplexml_load_string($content->pre);
$json = json_encode($content);
$content = json_decode($json,TRUE);
var_dump($content);
但是还是得到
的错误
Warning: simplexml_load_string(): Entity: line 1: parser error : StartTag: invalid element name in index.php on line 24
Warning: simplexml_load_string(): <![CDATA[<VEHICLEDETAILS><VEHICLE><ID>5002386176</ID><VIN>AHTHA3CD503427515</VIN in index.php on line 24
Warning: simplexml_load_string(): ^ in index.php on line 24
Warning: simplexml_load_string(): Entity: line 1: parser error : Extra content at the end of the document in index.php on line 24
Warning: simplexml_load_string(): <![CDATA[<VEHICLEDETAILS><VEHICLE><ID>5002386176</ID><VIN>AHTHA3CD503427515</VIN in index.php on line 24
Warning: simplexml_load_string(): ^ in index.php on line 24
bool(false)
在我无能为力的情况下,必须提供来自源的所有数据。
xml 解析器被不正确实体的 & 符号阻塞 &
-> &
<?php
$client = new SoapClient('http://www.autobid.co.za/halfway/vehicledetails.php?wsdl');
$result = $client->getVehicleDetails('spwf87','hk8*9jd');
//print_r($result);
$content = substr($result, strlen('<![CDATA['), -3);
$content=preg_replace('/&(?!#?[a-z0-9]+;)/', '&', $content);
$content = simplexml_load_string($content, 'SimpleXMLElement',LIBXML_NOCDATA);
foreach ($content->VEHICLE as $vehicle_props) {
echo "\n\n ---------------------";
foreach ($vehicle_props as $prop_name => $prop_value) {
if ($prop_name == "EXTRAS") $prop_value=implode("\n - ", explode(",", $prop_value));
echo "\n" . ucwords(strtolower($prop_name)) .": " . $prop_value;
}
}
经过多次尝试仍然没有成功,尝试访问这个'http://www.autobid.co.za/halfway/vehicledetails.php?wsdl,提供用户名和密码,然后收集xml 反馈。此代码:
$client = new SoapClient('http://www.autobid.co.za/halfway/vehicledetails.php?wsdl');
$result = $client->getVehicleDetails('spwf87','hk8*9jd');
echo('<pre>'.$result.'</pre>');
转储整个文本字段,当然希望按照页面源代码对其进行清理:
<pre><![CDATA[<VEHICLEDETAILS><VEHICLE><ID....
等,所以尝试使用:
$client = new SoapClient('http://www.autobid.co.za/halfway/vehicledetails.php?wsdl');
$result = $client->getVehicleDetails('pass','user');
$content = simplexml_load_string($result, null,LIBXML_NOCDATA);
$content = simplexml_load_string($content->pre);
$json = json_encode($content);
$content = json_decode($json,TRUE);
var_dump($content);
但是还是得到
的错误Warning: simplexml_load_string(): Entity: line 1: parser error : StartTag: invalid element name in index.php on line 24
Warning: simplexml_load_string(): <![CDATA[<VEHICLEDETAILS><VEHICLE><ID>5002386176</ID><VIN>AHTHA3CD503427515</VIN in index.php on line 24
Warning: simplexml_load_string(): ^ in index.php on line 24
Warning: simplexml_load_string(): Entity: line 1: parser error : Extra content at the end of the document in index.php on line 24
Warning: simplexml_load_string(): <![CDATA[<VEHICLEDETAILS><VEHICLE><ID>5002386176</ID><VIN>AHTHA3CD503427515</VIN in index.php on line 24
Warning: simplexml_load_string(): ^ in index.php on line 24
bool(false)
在我无能为力的情况下,必须提供来自源的所有数据。
xml 解析器被不正确实体的 & 符号阻塞 &
-> &
<?php
$client = new SoapClient('http://www.autobid.co.za/halfway/vehicledetails.php?wsdl');
$result = $client->getVehicleDetails('spwf87','hk8*9jd');
//print_r($result);
$content = substr($result, strlen('<![CDATA['), -3);
$content=preg_replace('/&(?!#?[a-z0-9]+;)/', '&', $content);
$content = simplexml_load_string($content, 'SimpleXMLElement',LIBXML_NOCDATA);
foreach ($content->VEHICLE as $vehicle_props) {
echo "\n\n ---------------------";
foreach ($vehicle_props as $prop_name => $prop_value) {
if ($prop_name == "EXTRAS") $prop_value=implode("\n - ", explode(",", $prop_value));
echo "\n" . ucwords(strtolower($prop_name)) .": " . $prop_value;
}
}