Skip to content

Latest commit

 

History

History
131 lines (98 loc) · 3.36 KB

README.md

File metadata and controls

131 lines (98 loc) · 3.36 KB

PHP Google Suggest

Latest Stable Version Total Downloads License

PHP Google suggest keyword tool. Google suggest search result.

Installation

PHP 5.4 is required.

The PHP Google Suggest Service Provider can be installed via Composer by requiring the euclid1990/php-google-suggest package in your project's composer.json.

{
    "require": {
        "euclid1990/php-google-suggest": "~1.0"
    },
    "minimum-stability": "stable"
}

or

Require this package with composer:

composer require euclid1990/php-google-suggest

Update your packages with composer update or install with composer install.

Setup

Commmon

Add boostrap autoload file:

require_once __DIR__ . '/../vendor/autoload.php';

use euclid1990\PhpGoogleSuggest\GoogleSuggest;

For Laravel

To use the Google Suggest Service, you must register the provider when bootstrapping your Laravel application. There are essentially two ways to do this.

Find the providers key in config/app.php and register the Google Suggest Service Provider.

    'providers' => [
        // ...
        'euclid1990\PhpGoogleSuggest\Providers\GoogleSuggestServiceProvider',
    ]

for Laravel 5.1+

    'providers' => [
        // ...
        euclid1990\PhpGoogleSuggest\Providers\GoogleSuggestServiceProvider::class,
    ]

Find the aliases key in config/app.php.

    'aliases' => [
        // ...
        'GoogleSuggest' => 'euclid1990\PhpGoogleSuggest\Facades\GoogleSuggest',
    ]

for Laravel 5.1+

    'aliases' => [
        // ...
        'GoogleSuggest' => euclid1990\PhpGoogleSuggest\Facades\GoogleSuggest::class,
    ]

Usage

1. Common PHP:

Please refer to demo/run.php or you can execute this command line:

# php demo/run.php
require_once __DIR__ . '/../vendor/autoload.php';

use euclid1990\PhpGoogleSuggest\GoogleSuggest;

$configArr = require __DIR__.'/../config/google_suggest.php';
$config = ['google_suggest' => $configArr];
$googleSuggest = new GoogleSuggest(new Illuminate\Config\Repository($config));

$english = 'Google';
$result = $googleSuggest->search($english, $configArr['language']);
echo "Search results for English keyword.\n";
print_r($result);

$japanese = 'あいうえお';
$result = $googleSuggest->search($japanese, $configArr['language']);
echo "Search results for Japanese keyword.\n";
print_r($result);

$vietnamese = 'tìm';
$result = $googleSuggest->search($vietnamese, $configArr['language']);
echo "Search results for Vietnamese keyword.\n";
print_r($result);

Result:

Preview

2. For Laravel

$keyword = 'suggest';
// Class method
\GoogleSuggest::search($keyword);
// Helper
google_suggest($keyword);

Reference

Packagist