{"id":15046809,"url":"https://github.com/serpapi/google-search-results-php","last_synced_at":"2025-04-05T19:13:29.810Z","repository":{"id":29569532,"uuid":"122037105","full_name":"serpapi/google-search-results-php","owner":"serpapi","description":"Google Search Results PHP API via Serp Api ","archived":false,"fork":false,"pushed_at":"2024-07-31T17:36:11.000Z","size":52,"stargazers_count":60,"open_issues_count":7,"forks_count":48,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-29T17:13:14.023Z","etag":null,"topics":["php","php-api","serp-api"],"latest_commit_sha":null,"homepage":"https://serpapi.com","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/serpapi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-19T08:43:29.000Z","updated_at":"2025-02-20T11:03:10.000Z","dependencies_parsed_at":"2024-06-18T19:57:31.839Z","dependency_job_id":"e2b86a99-8fbb-4dea-b508-3a5528ea5aa1","html_url":"https://github.com/serpapi/google-search-results-php","commit_stats":{"total_commits":54,"total_committers":11,"mean_commits":4.909090909090909,"dds":"0.33333333333333337","last_synced_commit":"3a2b4ccdbc7d34ab91b783d2447915e111435a3f"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serpapi%2Fgoogle-search-results-php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serpapi%2Fgoogle-search-results-php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serpapi%2Fgoogle-search-results-php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/serpapi%2Fgoogle-search-results-php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/serpapi","download_url":"https://codeload.github.com/serpapi/google-search-results-php/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247386265,"owners_count":20930619,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["php","php-api","serp-api"],"created_at":"2024-09-24T20:53:36.435Z","updated_at":"2025-04-05T19:13:29.783Z","avatar_url":"https://github.com/serpapi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Google Search Results in PHP\n\n[![PHP build](https://github.com/serpapi/google-search-results-php/actions/workflows/test.yml/badge.svg)](https://github.com/serpapi/google-search-results-php/actions/workflows/test.yml)\n\nThis PHP API is meant to scrape and parse Google, Bing or Baidu results using [SerpApi](https://serpapi.com).\n\n[The full documentation is available here.](https://serpapi.com/search-api)\n\nThe following services are provided:\n * [Search API](https://serpapi.com/search-api)\n * [Location API](https://serpapi.com/locations-api)\n * [Search Archive API](https://serpapi.com/search-archive-api)\n * [Account API](https://serpapi.com/account-api)\n\nSerpApi provides a [script builder](https://serpapi.com/demo) to get you started quickly.\n\n## Installation\n\n Php 7+ must be already installed and [composer](https://getcomposer.org/) dependency management tool.\n\n Package available from packagist.\n\n## Quick start\n\nif you're using composer, you can add this package ([link to packagist](https://packagist.org/packages/serpapi/google-search-results-php)).\n```bash\n$ composer require serpapi/google-search-results-php\n```\n\nThen you need to load the dependency in your script.\n```\n\u003c?php\nrequire __DIR__ . '/vendor/autoload.php';\n ?\u003e\n```\n\nif not, you must clone this repository and link the class.\n```php\nrequire 'path/to/google-search-results';\nrequire 'path/to/restclient';\n```\n\nGet \"your secret key\" from https://serpapi.com/dashboard\n\nThen you can start coding something like:\n```php\n$client = new GoogleSearch(\"your secret key\");\n$query = [\"q\" =\u003e \"coffee\",\"location\"=\u003e\"Austin,Texas\"];\n$response = $client-\u003eget_json($query);\nprint_r($response)\n ```\n\nThis example runs a search about \"coffee\" using your secret api key.\n\nThe SerpApi service (backend)\n - searches on Google using the query: q = \"coffee\"\n - parses the messy HTML responses\n - return a standardizes JSON response\nThe Php class GoogleSearch\n - Format the request to SerpApi server\n - Execute GET http request\n - Parse JSON into Ruby Hash using JSON standard library provided by Ruby\nEt voila..\n\nAlternatively, you can search:\n  - Bing using BingSearch class\n  - Baidu using BaiduSearch class\n  - Ebay using EbaySearch class\n  - Yahoo using YahooSearch class\n  - Yandex using YandexSearch class\n  - Walmart using WalmartSearch class\n  - Youtube using YoutubeSearch class\n  - HomeDepot using HomeDepotSearch class\n  - Apple App Store using AppleAppStoreSearch class\n  - Naver using NaverSearch class\n\nSee the playground to generate your code.\n https://serpapi.com/playground\n\n## Example\n * [How to set SERP API key](#how-to-set-serp-api-key)\n * [Search API capability](#search-api-capability)\n * [Location API](#location-api)\n * [Search Archive API](#search-archive-api)\n * [Account API](#account-api)\n * [Search Google Images](#search-google-images)\n * [Generic SerpApiClient](#serpapiclient)\n * [Example by specification](#example-by-specification)\n * [Composer example](#composer-example)\n\n### How to set SERP API key\nThe SerpApi api_key can be set globally using a singleton pattern.\n\n```php\n$client = new GoogleSearch();\n$client-\u003eset_serp_api_key(\"Your Private Key\");\n```\nOr\n\n```php\n$client = new GoogleSearch(\"Your Private Key\");\n```\n\n### Search API capability\n```php\n$query = [\n  \"q\" =\u003e  \"query\",\n  \"google_domain\" =\u003e  \"Google Domain\", \n  \"location\" =\u003e  \"Location Requested\", \n  \"device\" =\u003e  \"device\",\n  \"hl\" =\u003e  \"Google UI Language\",\n  \"gl\" =\u003e  \"Google Country\",\n  \"safe\" =\u003e  \"Safe Search Flag\",\n  \"num\" =\u003e  \"Number of Results\",\n  \"start\" =\u003e  \"Pagination Offset\",\n  \"serp_api_key\" =\u003e  \"Your SERP API Key\",\n  \"tbm\" =\u003e \"nws|isch|shop\"\n  \"tbs\" =\u003e \"custom to be search criteria\"\n  \"async\" =\u003e true|false # allow async \n];\n\n$client = new GoogleSearch(\"private key\");\n\n$html_results = $client-\u003eget_html($query);\n$json_results = $client-\u003eget_json($query);\n```\n\n### Location API\n\n```php\n$client = new GoogleSearch(getenv(\"API_KEY\"));\n$location_list = $client-\u003eget_location('Austin', 3);\nprint_r($location_list);\n```\nit prints the first 3 location matching Austin (Texas, Texas, Rochester)\n```php\n[{:id=\u003e\"585069bdee19ad271e9bc072\",\n  :google_id=\u003e200635,\n  :google_parent_id=\u003e21176,\n  :name=\u003e\"Austin, TX\",\n  :canonical_name=\u003e\"Austin,TX,Texas,United States\",\n  :country_code=\u003e\"US\",\n  :target_type=\u003e\"DMA Region\",\n  :reach=\u003e5560000,\n  :gps=\u003e[-97.7430608, 30.267153],\n  :keys=\u003e[\"austin\", \"tx\", \"texas\", \"united\", \"states\"]},\n  ...]\n```\n\n### Search Archive API\n\nLet's run a search to get a search_id.\n```php\n$client = new GoogleSearch(getenv(\"API_KEY\"));\n$result = $client-\u003eget_json($this-\u003eQUERY);\n$search_id = $result-\u003esearch_metadata-\u003eid\n```\n\nNow let's retrieve the previous search from the archive.\n\n```php\n$archived_result = $client-\u003eget_search_archive($search_id);\nprint_r($archived_result);\n```\n\nit prints the search from the archive.\n\n### Account API\n```ruby\n$client = new GoogleSearch($this-\u003eAPI_KEY);\n$info = $client-\u003eget_account();\nprint_r($info);\n```\nit prints your account information.\n\n### Search Google Images\n\n```php\n$client = new GoogleSearch(getenv(\"API_KEY\"));\n$data = $client-\u003eget_json([\n  'q' =\u003e \"Coffee\", \n  'tbm' =\u003e 'isch'\n]);\n\nforeach($data-\u003eimages_results as $image_result) {\n  print_r($image_result-\u003eoriginal);\n  //to download the image:\n  // `wget #{image_result[:original]}`\n}\n```\n\nthis code prints all the images links, \n and download image if you un-comment the line with wget (linux/osx tool to download image).\n\n## Example by specification\n\nThe code described above is tested in the file test.php and example.php.\nTo run the test locally. \n\n```php\nexport API_KEY='your secret key'\nmake test example\n```\n\n## Composer example\n\nsee: https://github.com/serpapi/google-search-results-php/example_composer/\n\nTo run the code.\n - git clone https://github.com/serpapi/google-search-results-php\n - cd google-search-results-php/example_composer/\n - make API_KEY=\u003cyourSecretKey\u003e all\n\n\n## Change log\n * 2.0\n   * Code refractoring SearchResult -\u003e Search\n   * Add walmart and youtube search engine\n * 1.2.0\n   * Add more search engine\n * 1.0\n   * First stable version\n## Conclusion\n\nSerpApi supports all the major search engines. Google has the more advance support with all the major services available: Images, News, Shopping and more.. To enable a type of search, the field tbm (to be matched) must be set to:\n\n - isch: Google Images API.\n - nws: Google News API.\n - shop: Google Shopping API.\n - any other Google service should work out of the box.\n - (no tbm parameter): regular Google search.\nThe field tbs allows to customize the search even more.\n\n[The full documentation is available here.](https://serpapi.com/search-api)\n\nAuthor: Victor Benarbia victor@serpapi.com\nFor more information: https://serpapi.com\n\nThanks Rest API for Php\n - Travis Dent  - https://github.com/tcdent/php-restclient\n - Test framework - PhpUnit - https://phpunit.de/getting-started/phpunit-7.html\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserpapi%2Fgoogle-search-results-php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fserpapi%2Fgoogle-search-results-php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fserpapi%2Fgoogle-search-results-php/lists"}