How to detect the language of a string in PHP

Cloudmersive
1 min readJul 31, 2019

--

Identifying the language of a string of text has been made incredibly easy with our Natural Language Processing (NLP) API. Begin by adding this reference to your library:

"require": {
"cloudmersive/cloudmersive_nlp_api_client": "^1.3",
}

Now just call the languageDetectionPost function, as follows:

<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
$apiInstance = new Swagger\Client\Api\LanguageDetectionApi(


new GuzzleHttp\Client(),
$config
);
$text_to_detect = "text_to_detect_example"; // string | Text to detect language of
try {
$result = $apiInstance->languageDetectionPost($text_to_detect);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling LanguageDetectionApi->languageDetectionPost: ', $e->getMessage(), PHP_EOL;
}
?>

And that’s a wrap. This API supports a wide variety of written languages including Spanish, German, French, Chinese, Korean, and many others. There are numerous other language related functions available as well, so be sure to check them out!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet