Page 1 of 1
grab data from site A and process it on site B
Posted: Wed Aug 17, 2011 10:22 pm
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
Re: grab data from site A and process it on site B
Posted: Thu Aug 18, 2011 1:35 am
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.
Re: grab data from site A and process it on site B
Posted: Thu Aug 18, 2011 6:01 am
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