How to Spellcheck a Sentence in PHP

Cloudmersive
1 min readMar 31, 2023

--

Equipped with our free Spellcheck a Sentence API, your application can rapidly identify incorrect spellings in full sentence strings and return a valuable array of corrections instantly. Each response is structured according to the example JSON below:

{
"IncorrectCount": 0,
"Words": [
{
"Word": {
"Word": "string",
"WordIndex": 0,
"StartPosition": 0,
"EndPosition": 0
},
"Correct": true,
"Suggestions": [
"string"
]
}
]
}

To structure your API calls with complementary, ready-to-run PHP code examples, begin by installing the client SDK using Composer. Execute the following command from the command line:

composer require cloudmersive/cloudmersive_nlp_api_client

After that, implement the examples below, and authenticate your requests by grabbing a free-tier API key from our website (register a free account to do so; this will provide you with a limit of 800 API calls per month and no commitments):

<?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\SpellcheckApi(


new GuzzleHttp\Client(),
$config
);
$value = new \Swagger\Client\Model\CheckSentenceRequest(); // \Swagger\Client\Model\CheckSentenceRequest | Input sentence

try {
$result = $apiInstance->spellcheckCheckSentence($value);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling SpellcheckApi->spellcheckCheckSentence: ', $e->getMessage(), PHP_EOL;
}
?>

That’s all the code you’ll need. Easy!

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet