grab data from site A and process it on site B

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
inosent1
Forum Commoner
Posts: 97
Joined: Wed Jan 28, 2009 12:18 pm

grab data from site A and process it on site B

Post by inosent1 »

there is a web page with a table that has a changing number in it on Site A. I want to use php to grab that number and display it on my site, place it in a form, store it to a DB and then do various calculations as the number of entries grow.

i want this to happen automatically. so once i open this php page, it pulls the data, and stores it to my mysql db every x intervals of time
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: grab data from site A and process it on site B

Post by Christopher »

Use a library like cURL or a function like file_get_contents() to grab contents of the page. You can search the page with string functions or regexp, or use the DOM library to parse the page. You need to use something like cron to run a program every x interval of time.
(#10850)
phphelpme
Forum Contributor
Posts: 261
Joined: Sun Nov 21, 2010 3:32 pm

Re: grab data from site A and process it on site B

Post by phphelpme »

Yes, you need to look into cURL for this.

cURL will connect you to site A from site B, you can load site A into a variable string($) and then use strpos() and substr() to locate the number value you want and extract it from your initial string($) as another string($).

Then you can do what you want with the value with forms and calculations and database entries.

Then you setup a cron job to run X interval that way you dont need to have the page open the server can run this code for you.

Checkout these links:

http://php.net/manual/en/book.curl.php

http://uk3.php.net/manual/en/function.strpos.php

http://uk3.php.net/manual/en/function.substr.php

and you may need strip_tags if you strip html content too:

http://uk3.php.net/manual/en/function.strip-tags.php

Best wishes
Post Reply