This is an old post. The information it contains is probably out of date or innacurate
This is a post that was written a long time ago and is only being kept here for posterity. You should probably look up more recent blog posts related to the subject you are researching
One of the most useful and powerful things you can do with PHP is to create a programme which will simulate a web browser and can grab data, post data to forms and generally interact with other web sites – automatically.
For PHP to be able to work like this it must have the CURL library installed and active. It is the CURL library which actually handles all of the interaction and PHP is my scripting language of choice for interacting with CURL.
A simple CURL function is like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
This function when called and echoed will output the entire html of the $url specified.
For grabbing data from this page to be inserted into a database (for example when spidering a suppliers web site for product information to be inserted into your site) we then use regular expressions to find what we are looking for and then insert that into the database.
so for example if we wanted to grab the product title and we knew that this was wrapped in a h1 tag with the class “product title” we could use this regexp to grab this:
1 2 3 4 5 6 7 8 9
We can also Post data to web sites using curl. This allows us to do all kinds of things including grabbing data that is displayed on the submission of post forms. Here is an example Curl Post Function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
It can be tricky to figure out exactly what data should be in the post string. To help you out though is this incredibly handy addon for firefox: Live Http Headers.
This addon lets you see exactly what is going on between your browser and the web site you are visiting. This can quickly and easily give you the information you need to replicate the same behaviour with your CURL script.
Edmonds Commerce specialise in working with PHP and CURL. If you have any spidering, screen scraping or other application that requires PHP to actively interact with other web sites – get in touch today to see how we can help you benefit from this incredibly powerful technique.