Get the App
SLTechnology News&Howtos  ›  Development  › 

How PHP accesses Google Search API

Shulou Source: shulou.com Published: 2022-06-03 19:46:59 11月12日 Update

This article is about how PHP accesses Google Search API. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The details are as follows:

This code snippet demonstrates how to send a request from php to the AJAX search API. Note that this example assumes the use of PHP 5.2. For earlier installations of PHP, please refer to the corresponding official comments.

The specific code is as follows:

$url = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&q=Paris%20Hilton"; / / sendRequest// note how referer is set manually$ch = curl_init (); curl_setopt ($ch, CURLOPT_URL, $url); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($ch, CURLOPT_REFERER," http://www.mysite.com/index.html");$body = curl_exec ($ch); curl_close ($ch)) / / now, process the JSON string$json = json_decode ($body); / / now have some fun with the results... Thank you for reading! This is the end of the article on "how PHP accesses Google Search API". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Code content more articles references good practical official articles comments see knowledge examples help search related demo Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Xiaomi NVidia Shulou Technology Microsoft