Automatically display "Google Adsense for Search" results
I am working on a website that uses PHP/MySQL to search the website's database and display results. In addition, I now want to display results from Google Adsense for search, but without the user having to manually enter search terms into the search box.
So say the user selects the following variables for the database search:
$var1 = apples;
$var2 = pears;
$var3 = cake;
Then I want to also display search results from Google Adsense for search, as if the user had entered the following into the search box: "cake apples pears". Or so开发者_运维问答mething along those lines anyway.
So probably that's a bit of an indirect way of explaining what I want to do, but hopefully it's clear. How do I do this? I'm thinking along the lines of having Javascript enter the search terms automatically into the searchbox, but maybe there is a much more straightforward way without having to display/use a searchbox at all?
Thanks a lot!
Using Curl, like this :
$var1 = 'apples';
$var2 = 'pears';
$var3 = 'cake';
$query= $var1 . '+' . $var2 . '+' . $var3;
$ch=curl_init();
curl_setopt ($ch, CURLOPT_URL, "http://www.google.com/support/adsense/bin/search.py?query=$query");
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec ($ch);
curl_close($ch); // good practice to close connection, it can save a lot of time in some cases.
echo $data;
精彩评论