Hello, I am supposed to construct a page that searches in specific websites to extract information, like those sites from where you can rent a car for example. There is a form in the site where the user selects some fields (for instance departure and drop-off date), then the data are submitted to the other page that searches 2-3 sites and finds which cars are available on those dates. I wanted to ask if there are ready scripts to do that, if not, some hints on how to start. I am familiar with PHP forms and data extraction from mysql databases, but when you extract data from other sites, I have no clue how I can begin and deal with it...
Well I'm not going to do your homework for you, but I can give you a few functions that might help. php.net/curl Or (if no post data is required) php.net/file_get_contents And php.net/preg_match php.net/preg_match_all I guess these are the most important. (Sorry for the not clickable links, I'm not yet allowed to post some)
Clickable: www.php.net/curl php.net/file_get_contents php.net/preg_match php.net/preg_match_all As nico_swd says, they should be all you need. I'll also include this function, you'll need it during development. I also find strip_tags useful for data extraction.
I like to use this: function gofetch() { $fp = @fsockopen("www.website.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET /anythingyouwant.html HTTP/1.1\r\n"; $out .= "Host: www.website.com\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { $d = fgets($fp); if (preg_match("/searching for/i", $d)) { echo "I found it :" . $d; } } } } PHP: