PHP Classes

File: example/suggest.php

Recommend this page to a friend!
  Classes of Cesar D. Rodas   Autocomplete   example/suggest.php   Download  
File: example/suggest.php
Role: Example script
Content type: text/plain
Description: First commit
Class: Autocomplete
Suggest words to complete search using edge n-gram
Author: By
Last change:
Date: 11 years ago
Size: 356 bytes
 

Contents

Class file image Download
<?php

require __DIR__ . "/../vendor/autoload.php";

use
crodas\Autocomplete\Autocomplete;
use
crodas\Autocomplete\PDOConn;

$pdo = new PDO("sqlite:data.db");
$conn = new PDOConn($pdo);
$suggest = new Autocomplete($conn);

$words = [];
foreach (
$suggest->suggest($_GET['term']) as $word) {
   
$words[] = $word['word'];
}

echo
json_encode($words);