我正在尝试通过ean产品创建一个从Icecat目录中提取,重量或高度....的功能。
你对synthax有什么想法吗?
我很少丢失所有数据。
谢谢。
// call catalog
public function getSearchProductEanXML() {
$ean = $this->ean;
$language = $this->lang;
if($this->ean == null) {
return 0;
}
$url = 'http://data.icecat.biz/xml_s3/xml_server3.cgi?ean_upc=' . $ean . ';lang=' . $language . ';output=productxml';
$context = stream_context_create(array('http' => array( 'header' => "Authorization: Basic " . base64_encode($this->username . ":" . $this->password) )));
$data = file_get_contents($url, false, $context);
$xml = new SimpleXMLElement($data);
return $xml;
}
// function to extract weight
public function getProductWeight() {
$xml = $this->getSearchProductEanXML();
$product_pdf_weight = $xml->xpath("//ProductFeature");
foreach($product_pdf_weight as $item) {
$weight = $item->attributes();
var_dump($weight);
var_dump('<hr>');
// $WeightItem = new SimpleXMLElement($item->asXML());
// $weight = $WeightItem->xpath("//Name");
// var_dump($weight);
// $weight = $weight['Value'];
}
exit;
return $weight;
}
$ean = '0013803146813';
$icecat = new IceCat($ean, 'en');
echo '<br>';
echo $icecat->getProductWeight();
" array(1) { [0]=> object(SimpleXMLElement)#57 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "2715" ["langid"]=> string(1) "1" ["Value"]=> string(17) "Maximum scan size" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#56 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "2985" ["langid"]=> string(1) "1" ["Value"]=> string(27) "Optical scanning resolution" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#55 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "3131" ["langid"]=> string(1) "1" ["Value"]=> string(15) "Colour scanning" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#57 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(5) "30724" ["langid"]=> string(1) "1" ["Value"]=> string(15) "Duplex scanning" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#56 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(6) "615813" ["langid"]=> string(1) "1" ["Value"]=> string(18) "Input colour depth" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#55 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(6) "615854" ["langid"]=> string(1) "1" ["Value"]=> string(19) "Output colour depth" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#57 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "1445" ["langid"]=> string(1) "1" ["Value"]=> string(17) "Gray scale levels" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#56 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "2605" ["langid"]=> string(1) "1" ["Value"]=> string(12) "Scanner type" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#55 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "5487" ["langid"]=> string(1) "1" ["Value"]=> string(17) "Colour of product" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#57 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "4899" ["langid"]=> string(1) "1" ["Value"]=> string(11) "Sensor type" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#56 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(6) "619793" ["langid"]=> string(1) "1" ["Value"]=> string(22) "Daily duty cycle (max)" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#55 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "5543" ["langid"]=> string(1) "1" ["Value"]=> string(12) "Light source" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#57 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "3177" ["langid"]=> string(1) "1" ["Value"]=> string(41) "Auto document feeder (ADF) input capacity" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#56 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(6) "619834" ["langid"]=> string(1) "1" ["Value"]=> string(30) "Scanning media types supported" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#55 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(5) "11529" ["langid"]=> string(1) "1" ["Value"]=> string(39) "Auto Document Feeder (ADF) media weight" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#57 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(6) "615486" ["langid"]=> string(1) "1" ["Value"]=> string(19) "Standard interfaces" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#56 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "2257" ["langid"]=> string(1) "1" ["Value"]=> string(27) "Power consumption (typical)" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#55 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "9104" ["langid"]=> string(1) "1" ["Value"]=> string(27) "Power consumption (standby)" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#57 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(5) "27753" ["langid"]=> string(1) "1" ["Value"]=> string(15) "Input frequency" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#56 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "4629" ["langid"]=> string(1) "1" ["Value"]=> string(13) "Input voltage" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#55 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(6) "617692" ["langid"]=> string(1) "1" ["Value"]=> string(35) "Windows operating systems supported" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#57 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "3765" ["langid"]=> string(1) "1" ["Value"]=> string(27) "Operating temperature (T-T)" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#56 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "2937" ["langid"]=> string(1) "1" ["Value"]=> string(33) "Operating relative humidity (H-H)" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#55 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "9056" ["langid"]=> string(1) "1" ["Value"]=> string(27) "Operating temperature (T-T)" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#57 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "3207" ["langid"]=> string(1) "1" ["Value"]=> string(21) "Energy Star certified" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#56 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "1525" ["langid"]=> string(1) "1" ["Value"]=> string(6) "Weight" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#55 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "5143" ["langid"]=> string(1) "1" ["Value"]=> string(5) "Width" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#57 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "5145" ["langid"]=> string(1) "1" ["Value"]=> string(5) "Depth" } } } string(4) "" array(1) { [0]=> object(SimpleXMLElement)#56 (1) { ["@attributes"]=> array(3) { ["ID"]=> string(4) "4625" ["langid"]=> string(1) "1" ["Value"]=> string(6) "Height" } } }