How can I combine several Import.io search engine connectors into one search engine with PHP?

I have a PHP API PHP code from a data / website extraction tool ( http://import.io ) in the form below. I want to have a search box that returns not one, but several of these “connector” code blocks (they are called connectors because they associate your search queries with results that are apparently passed through import.io).

I am noob in PHP, so I'm not sure how to do this.

<?php

$userGuid = "kjnjkn-32d2-4b1c-a9c5-erferferferferf";
$apiKey = "APIKEY";

function query($connectorGuid, $input, $userGuid, $apiKey) {

  $url = "https://api.import.io/store/connector/" . $connectorGuid . "/_query?_user=" . urlencode($userGuid) . "&_apikey=" . urlencode($apiKey);

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  curl_setopt($ch, CURLOPT_POSTFIELDS,  json_encode(array("input" => $input)));
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  $result = curl_exec($ch);
  curl_close($ch);

  return json_decode($result);
}

// Query for tile WEBSEARCH
$result = query("98c9bac2-e623-4e31-8a3e-erferferferf", array(
  "search_query" => "term1",
), $userGuid, $apiKey);
var_dump($result);

// Query for tile WEBSEARCH
$result = query("98c9bac2-e623-4e31-8a3e-bferfreferfe", array(
  "search_query" => "term2",
), $userGuid, $apiKey);
var_dump($result);
+4
source share
1 answer

, , , - HTML-, POST PHP script. , - :

<form action="path/to/myscript.php" method="POST">
    <input type="text" name="search" placeholder="query">
    <input type="submit" value="Search">
</form>

HTTP POST script ( myscript.php HTML ) $_ POST .

, $_POST["search"] :

$result = query("98c9bac2-e623-4e31-8a3e-erferferferf", array(
  "search_query" => $_POST["search"],
), $userGuid, $apiKey);
var_dump($result);

:

  • - , -
  • PHP .
  • , import.io(, !)
+5
source

All Articles