Code to look up on a remote site for price changes on a particular product

I am trying to make a application that trys to remotely searchs for a string on the page

heres my code i am trying to progrm ive attempted curl but no luck as im storing all my prices so far from me in a db and want to make sure if the price changes then i get alerted so heres my code maybe its not a good way to do it but i tried url not sure anyhow here it is

$link = "THESITE.COM";
$linkcontents = fopen($link,'r');
$needle = "125.99";
if (strpos($linkcontents, $needle) == false) {
echo "Price has changed.";
} else {
echo "String found";

What do you guys recommend?

Does the site you’re accessing not provide any kind of API to access their price and product data?

Sorry for late reply some of the sources do not provide an api

If there’s no API available, you’ll have to scrape the relevant pages to get the data you’re after. Take a look at this HTML DOM parser library for PHP, I’ve used it before for similar projects.

Try this:

Curl Demo with Source code

Your supplied link, is redirected?

I would recommend testing a simple site first.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.