...

View Full Version : Shopping.com PHP Script is skipping groups...why?



angmi90
12-06-2008, 05:05 PM
I have a PHP code that is as follows...



<?php
error_reporting(0);
@ini_set(‘display_errors’, 0);
$product_specs_xml = new product_specs_xml;

$product_specs_xml->readXML($_GET['pid']);


class product_specs_xml
{
function readXML($productId)
{
$this->xml = file_get_contents("http://publisher.api.shopping.com/publisher/3.0/rest/GeneralSearch?apiKey=REMOVED&trackingId=REMOVED&productId=$productId&showProductSpecs=true&numItems=0");
$groups = $this->parse_tags('featureGroup',$this->xml);
foreach($groups as $g)
{
preg_match('%<name\b[^>]*>(.*?)</name>%',$g,$featurename);
$featureGroups["$featurename[1]"] = array();
preg_match_all('%<feature\b[^>]*>(.*?)</feature>%',$g,$feature);
foreach($feature[1] as $f)
{
preg_match('%<name\b[^>]*>(.*?)</name>%',$f,$name);
preg_match('%<value\b[^>]*>(.*?)</value>%',$f,$value);
$featureGroups["$featurename[1]"]["$name[1]"] = $value['1'];
}
}
foreach($featureGroups as $group => $features)
{
$this->rows .= "<thead>
<tr>
<th colspan=\"2\">$group</th>
</tr>
</thead>";
foreach($featureGroups[$group] as $name => $value)
{
$this->rows .= "<tr><td>$name</td><td>$value</td></tr>";
}
}
$this->output();
}

function parse_tags($tag,$src)
{
preg_match_all("%<$tag\b[^>]*>(.*?)<$tag>%",$src,$matches);
return $matches['1'];
}

function output()
{
echo '<div class="testReportChart">
<table class="testReportTable">';
echo $this->rows;
echo '</table>
</div>';
}
}
?>


and it uses an XML script like this http://sandbox.api.shopping.com/publisher/3.0/rest/GeneralSearch?apiKey=authorized-key&trackingId=7000610&productId=45041151&showProductSpecs=true&numItems=0 but when it displays the <featureGroup> information in that tag, it shows the first one, then skips the second one, then shows the third one, then skips the 4th...and so on.

With that particular link to that XML file, it shows the ProductMPN, Audio Capabilities, Screen, Other Features, and Dimensions <featureGroup>'s, but it skips the ones inbetween.

Why does this happen and how do I fix it? Thanks.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum