Hello,
I am making an addition to a shopping cart script and require the ability to puul live rates from ups. The problem is that I can't figure out how to get the different rates. I am only able to pull the first rate (UPS Next Day Air Early A.M.®) but I need to also pull the ups ground rates and the UPS 2nd Day Air® rates.
The following code is the function that is used.
function GetUPSGroundPrice($from_country, $from_city, $from_zip, $to_country, $to_city, $to_zip, $to_residential, $pounds)
{
$q="";
$p="";
$matchcount = 0;
$ss = "align=middle vAlign=center colspan=1><B>";
$pounds=intval($pounds);
$from_city = str_replace(" ", "%20", $from_city);
$to_city = str_replace(" ", "%20", $to_city);
$url="http://wwwapps.ups.com/servlet/QCCServlet?iso_language=en&iso_country=US&origcountry=".$from_country."&origpostal=".$from_zip."&origincity=".$from_city."&destcountry=".$to_country."&destpostal=".$to_zip."&destcity=".$to_city."&residential=".$to_residential."&packages=1&rate_chart=RTP&container=21¤cycode=USD&weight1=2&weight_std1=LBS&length1=&width1=&height1=&length_std1=IN&value1=&ratesummarypackages.x=42&ratesummarypackages.y=8";
//$url="http://wwwapps.ups.com/servlet/QCCServlet?iso_language=en&iso_country=US&origcountry=".$from_country."&origpostal=".$from_zip."&origincity=".$from_city."&destcountry=".$to_country."&destpostal=".$to_zip."&destcity=".$to_city."&residential=".$to_residential."&packages=1&rate_chart=RTP&container=02¤cycode=USD&weight1=".$pounds."&weight_std1=LBS&length1=4&width1=5&height1=6&length_std1=IN&value1=&ratesummarypackages.x=34&ratesummarypackages.y=11";
//debug
//echo("$url<p>\n");
@$fp=fopen($url,"r");
if ($fp!=false)
{
while (!feof($fp))
{
$q.=fread($fp,80);
}
fclose($fp);
$ss= "align=middle vAlign=center colspan=1><B>";
$e = stristr($q,$ss);
$e=substr($e,strlen($ss));
for ($a=0;$a<strlen($e);$a++)
{
$c=substr($e,$a,1);
if ($c=="<") $a=strlen($e); else $p.=$c;
}
}
$p=doubleval($p);
if ($p==0.00) {
$p=intval(($pounds+1)/4.00-0.01)*7.95+7.95;
}
return $p;
}
?>
it is then called with:
//ups info
$upsprice=GetUPSGroundPrice($orig_country,$orig_city,$orig_zip,$Ship_country,$Ship_Addr[City],$Ship_Addr[Postal_Code],YES,$Weight_Total);
echo("The UPS Ground price is: ".sprintf("$ %.2f",$upsprice)."<p>");
Basically I need to know how to get say the 3rd and 12th occurance of a specific string match then load it and disect it into usable rates.
The above code works perfectly but it only gets the first occurance of the string.
Any help will be greatly appreciated.