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
grab data from site A and process it on site B
Moderator: General Moderators
- 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
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)
Re: grab data from site A and process it on site B
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
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