PHP Classes

File: Usage.md

Recommend this page to a friend!
  Classes of Maik Greubel   DuckDuckGo PHP API client   Usage.md   Download  
File: Usage.md
Role: Documentation
Content type: text/markdown
Description: Usage description
Class: DuckDuckGo PHP API client
Search for data and related topics from DuckDuckGo
Author: By
Last change:
Date: 6 years ago
Size: 541 bytes
 

Contents

Class file image Download

Usage

composer.json

{
    "require" : {
        "php" : ">=7.0",
        "nkey/ddg-api" : "dev-master"
    }
}

Example php script:

use Nkey\DDG\API\JsonProvider;
use Nkey\DDG\API\QueryResultParser;

$provider = new JsonProvider();
$json = $provider->query("mount rushmore");

$parser = new QueryResultParser();
$results = $parser->parseQueryResult($json);

foreach($results->getRelatedTopics() as $relatedTopic) {
    printf('<a href="%s">%s</a>', $relatedTopic->getFirstURL(), $relatedTopic->getText());
}