By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,264 Members | 1,228 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,264 IT Pros & Developers. It's quick & easy.

Undefined Offset

P: 3
Hi,
I'm getting this error "Undefined offset" for the lines $price=$match[1];
$in_stock=$match[1];

Below is the code. Please help me to solve this and also i need extract from website using php. Your help is highly appreciated . Thanks for ur time.

<?php
$content = file_get_contents('http://www.sparkfun.com/commerce/product_info.php?products_id=9279');

preg_match('#<tr><th>(.*)</th> <td><b>price</b></td></tr>#', $content, $match);
$price = $match[1];

preg_match('#<input type="hidden" name="quantity_on_hand" value="(.*?)">#', $content, $match);
$in_stock = $match[1];

echo "Price: $price - Availability: $in_stock\n";
?>
Sep 29 '11 #1
Share this Question
Share on Google+
4 Replies


100+
P: 1,059
use print_r function to make sure that this index exists...
Sep 29 '11 #2

P: 3
thank u so much. can u pls specify where to change . i'm a newbie to php. pls help .
Sep 29 '11 #3

100+
P: 1,059
It wont give you the solution, but it will help you to debug.

use the function after calling file_get_contents
Sep 29 '11 #4

P: 3
Thank u so much for ur time!!
Sep 29 '11 #5

Post your reply

Sign in to post your reply or Sign up for a free account.