Version: 1
Type: Function
Category: Other
License: GNU General Public License
Description: Retrieve & parse wedding registry information for a Bed, Bath, and Beyond online registry given the registry number. Fills an array with item description, price, UPC, # requested, and # purchased.
<?php
//
// Registry-bbb.php 1.0 -- Goes out to the printable version of Bed, Bath, and Beyond's wedding registry website and retrieves all items awaiting purchase
// Originally developed for a wedding website to allow something better than just linking to their website.
// Fills an array with the structure $registry[] with ['desc'] = Description, ['UPC'] = UPC code / color, ['price'] = obvious, ['ask'] = quantity requested, ['have'] = quantity purchased
// NOTE: You must define $regnum with your registry number
// More releases will follow as we register other places.
// Released under the GPL - do what you like with it, but don't blame me if it breaks something. Sending this out because I wish I hadn't had to learn what little I actually know about regular expressions in order to code this.
// Code is probably ugly as I've not coded anything in YEARS, so bear with the mistakes and send suggestions for improvements to:
// bakerser@notes.udayton.edu.
// Thanks, and enjoy
//
$c = curl_init();
$regnum = 'YOUR REGISTY NUMBER HERE';
curl_setopt($c, CURLOPT_URL, 'http://www.bedbathandbeyond.com/regGiftRegistry.asp?order_num=-1&WRN=-$regnum&st=D&smode=prt&show_images=Y&RNT=0&IPPREG=100&IPPREGPRT=100');
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$p = curl_exec($c);
$p = addcslashes($p, "\0..\37!@\@\177..\377");
preg_match_all('(&sku=[0-9]*">[^<]*</a>|border=0><br>( )?[0-9a-zA-Z$\.&;\s<>^/]*?</td>)',$p,$num);
foreach ($num[0] as $item) {
$item = strip_tags($item);
$item_tmp = explode('>',$item);
$item_tmp = $item_tmp[1];
$j=$i%5;
$k=($i-$j)/5;
switch ($j) {
case 0:
$registry[$k]['desc']=$item_tmp;
break;
case 1:
$item_tmp = preg_replace('( )',' ',$item_tmp);
$registry[$k]['UPC'] = trim($item_tmp);
break;
case 2:
$item_tmp = preg_replace('( )',' ',$item_tmp);
$registry[$k]['price'] = trim($item_tmp);
break;
case 3:
$registry[$k]['ask'] = $item_tmp;
break;
case 4:
$registry[$k]['have'] = $item_tmp;
break;
}
$i++;
}
?>