views:

32

answers:

1

hi

I would like to grab the prices of products from newegg. heres an example site

http://www.newegg.com/Product/Product.aspx?Item=**N82E16820167027**

from this site, i would like to get the content of <div class="grpPricing">, that contains the price.

im not very skilled at making codes, so i was searching the web for codes and used it as an example to make my own... heres the result so far:

 function getprice($itemId) {
    $source=trim("http://www.newegg.com/Product/Product.aspx?Item=".$itemId);

    preg_match("'<div class=\"grpPricing\">(.*?)</div>'si", $source, $match);
    if($match) 
       echo "result=".$match[1];
 }

$itemId is given, this is how i can make a script that loops through multiple newegg products and gets the needed info

NOTE: it wont let me post the code as it really should be, dont know why, maybe because im not registered?!

and theres another issue that i cant solve... the output of the code should be:

return strip_tags($price);

simply because later i would call the function with this line

$price=getprice($row['newegg_productid']);

ive tried my best to explain clearly, but let me know if you have trouble understanding. any help is much appreciated, thanks!

+1  A: 

For your headstart:

<?php
function get_string_between($string, $start, $end)
{
    $string = " ".$string;
    $ini = strpos($string,$start);
    if ($ini == 0)
        return "";
    $ini += strlen($start);
    $len = strpos($string,$end,$ini) - $ini;
    return substr($string,$ini,$len);
}
$data = file_get_contents("http://www.newegg.com/Product/Product.aspx?Item=N82E16820167027");

$pricediv = get_string_between($data, '<div class="grpPricing">', '<div class="grpAction">');

$pricetext = strip_tags($pricediv);

echo $pricetext;
?>
shamittomar
this piece of code works very well on its own! but after one problem comes another... i cant integrate it into the code i already got...because of the character limitation ive decided to open a new question for that issue, which you can find here: http://stackoverflow.com/questions/3592916/integrating-a-functionthanks for your help!
crashtest