Example
<?php
# Description: Language Recognizer API usage example.
# Copyright: (C) 2016 EffectiveSoft Ltd. All Rights Reserved.
# Technical support: technical-support@effective-soft.com
header('Content-Type: text/plain');
# sample text
$text = "Ces droits et tous les autres, ne sont que des manisfestations concrète du droit général a l'existence et à l'acquisition de sa fin. Ces déterminations doivent provenir du fait.";
# ----------- cURL -----------
# set the URL for POST request and specify API key for authorization purposes (change YourAPIKey to the Intellexer API key)
$link = "http://api.intellexer.com/recognizeLanguage?apikey=YourAPIKey";
$header = array('Content-type: application/octet-stream');
# curl connection initialization
$ch = curl_init();
#set cURL options
curl_setopt_array($ch, array(
CURLOPT_URL => $link,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HEADER => false,
CURLOPT_HTTPHEADER => $header,
CURLOPT_POSTFIELDS => $text,
CURLOPT_FOLLOWLOCATION => true
));
# perform the request
$results = curl_exec($ch);
# error checking
if (curl_errno($ch))
{
echo 'CURL error: ' . curl_error($ch);
}
else
{
# parse JSON results
$json_results = json_decode($results, true);
# print information
$languages = $json_results['languages'];
foreach ($languages as $lang) {
echo 'Language ' . $lang['language'] . "\n";
echo 'Encoding ' . $lang['encoding'] . "\n";
echo 'Weight ' . $lang['weight'] . "\n";
}
}
curl_close($ch);
# ----------- END cURL -----------
Output
Language French
Encoding utf-8
Weight 9.11012893258