PHP code example of qryma-ai / qryma-php

1. Go to this page and download the library: Download qryma-ai/qryma-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

qryma-ai / qryma-php example snippets


// To install: composer dor/autoload.php';

use function Qryma\qryma;

$client = qryma(['apiKey' => 'ak-********************']);

$response = $client->search('artificial intelligence', ['lang' => 'en']);

print_r($response);



use function Qryma\qryma;

$client = qryma(['apiKey' => 'ak-********************']);

$response = $client->search('python programming');

// Access the organic results
$results = $response['organic'] ?? [];
foreach ($results as $result) {
    echo $result['title'] . "\n";
    echo $result['link'] . "\n";
    echo $result['snippet'] . "\n";
    echo "\n";
}



use function Qryma\qryma;

$client = qryma(['apiKey' => 'ak-********************']);

$response = $client->search('machine learning tutorials', [
    'lang' => 'en',
    'safe' => false,
    'mode' => 'snippet',
    'maxResults' => 5
]);

$results = $response['organic'] ?? [];
echo 'Found ' . count($results) . ' results' . "\n";



use Qryma\SearchOptions;

$client = qryma(['apiKey' => 'ak-********************']);

$options = new SearchOptions([
    'lang' => 'en',
    'safe' => true
]);

$response = $client->search('python programming', $options);

print_r($response);



use function Qryma\qryma;

$client = qryma([
    'apiKey' => 'ak-********************',
    'baseUrl' => 'https://custom.qryma.com',
    'timeout' => 60
]);
$response = $client->search('test query');
print_r($response);

[
  "organic" => [
    [
      "title" => "Result Title",
      "date" => "",
      "link" => "https://example.com",
      "position" => 1,
      "site_name" => "Example.com",
      "snippet" => "Description text...",
      "text" => "Full text..."
    ]
  ]
]



use Qryma\QrymaClient;

$client = new QrymaClient('ak-********************');
$response = $client->search('artificial intelligence');
print_r($response);



use function Qryma\qryma;

$client = qryma(['apiKey' => getenv('QRYMA_API_KEY')]);



use function Qryma\qryma;

try {
    $client = qryma(['apiKey' => 'ak-********************']);
    $response = $client->search('test query');
    $results = $response['organic'] ?? [];
    // Process results...

} catch (RuntimeException $e) {
    if (strpos($e->getMessage(), 'timed out') !== false) {
        echo 'Network timeout error';
    } elseif (strpos($e->getMessage(), 'API request failed') !== false) {
        echo 'API error';
    } else {
        echo 'Error: ' . $e->getMessage();
    }
}
bash
composer 
bash
./vendor/bin/phpunit tests/TestSearch.php