PHP Integration Tutorial

Add AI-powered semantic search to your PHP website in under 5 minutes

Available now15 minute readPHP 7.4+

What you'll build

By the end of this tutorial, you'll have a working semantic search that understands natural language queries. Users searching for "gift for girlfriend" will find relevant products even if they don't contain those exact keywords.

Table of Contents


Prerequisites

Before you start, make sure you have:

  • PHP 7.4 or higher - Check with php -v
  • cURL extension enabled - Usually enabled by default
  • Queryra API key - Sign up for free to get one

No installation required! This tutorial uses native PHP cURL - no Composer dependencies.


Quick Start (5 Minutes)

Step 1: Get Your API Key

  1. Sign up at queryra.com/signup
  2. Go to your dashboard
  3. Navigate to "API Keys"
  4. Click "Create API Key"
  5. Copy the key (starts with sk_live_)

Step 2: Make Your First Search Request

Create a file called search.php:

<?php
// Your API key from dashboard
$apiKey = 'sk_live_YOUR_API_KEY_HERE';

// Search query
$query = isset($_GET['q']) ? $_GET['q'] : 'laptop';

// Make API request
$url = 'https://api.queryra.com/api/v1/search?' . http_build_query([
    'q' => $query,
    'key' => $apiKey,
    'limit' => 5
]);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);

// Parse response
$data = json_decode($response, true);

// Display results
echo "<h1>Search Results for: " . htmlspecialchars($query) . "</h1>";

foreach ($data['results'] as $result) {
    echo "<div style='border: 1px solid #ccc; padding: 15px; margin: 10px 0;'>";
    echo "<h3 className="text-xl font-semibold text-gray-900 mt-6 mb-3">" . htmlspecialchars($result['name']) . "</h3>";
    echo "<p>Price: $" . number_format($result['price'], 2) . "</p>";
    echo "<p>Relevance: " . round($result['relevance_score'] * 100) . "%</p>";
    echo "<a href='" . htmlspecialchars($result['url']) . "'>View Product</a>";
    echo "</div>";
}
?>

Step 3: Test It!

Run your PHP server and open in browser:

php -S https://queryra.com
# Open: http://https://queryra.com/search.php?q=laptop+for+programming

Congratulations! You just implemented semantic search.


Last updated: January 14, 2026