You are not logged in. Sign in or register.

#1 2019-05-07 22:18:53

dave
Developer
Registered: 2018-11-09
Posts: 161
Website

Simple PHP example

Below is a simple example of how to use the api with PHP.

1: Create a file named "index.html" and add the following source code:

<form type="GET" action="search.php">
  <input type="text" name="query"/>
  <input type="submit" value="search..."/>
</form>

2: Create a file named "search.php" and add the following source code.

<?php

// set your api-key
$key = 'YOUR API KEY';

// set your name
$name = 'YOUR NAME';

// Get query from form GET
$query = $_GET['query'];

//build curl url
$offset = 0;
$lang = 'en';
$format = 'json';
$url = 'https://api.qmeta.net/conn.php?key='.$key.'&query='.$query.'&offset='.$offset.'&lang='.$lang.'&format='.$format;

// run curl with options
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $url,
    CURLOPT_USERAGENT => $name
));
$resp = curl_exec($curl);
curl_close($curl);
$output = json_decode($resp, true);

//output results as foreach
?>
<ol>
<?php
foreach ($output['results']['list'] as $item){
  ?>
  <li>
    <a href="<?php echo $item['link']; ?>"><img src="<?php echo $item['favicon']; ?>" width="20px"/> <?php echo $item['title']; ?></a>
    <br/>
    <p><?php echo $item['description']; ?></p>
  </li>
  <?php
}
?>
</ol>

3. Insert your data in "$key" and "$name".

4: Save the files in the same folder and upload it to your webserver.

5. Open the index.html in your browser.

https://github.com/dave-4k/qmeta/tree/master/api/php/


Senior-Developer and System-Administrator. Don't fuck with a Hacker's machine!

Offline