Sapling Logo
Grammar API quickstart

PHP Grammar Checker

Add spelling and grammar suggestions to a PHP application with Sapling's edits API.

  • HTTPS POST
  • HTTP API
  • API key required
POST PHP logo PHP /api/v1/edits

PHP grammar checker quickstart

Send text to the edits endpoint. Sapling returns suggested replacements with character offsets so your application can review or apply each correction.

No language-specific SDK is required. The example uses a standard or commonly used HTTP client to call Sapling's JSON API.
PHP /api/v1/edits

$url = 'https://api.sapling.ai/api/v1/edits';
$key = '<API_KEY>';
$postdata = json_encode(array(
    'key' => $key,
    'text' => 'Lets get started!',
    'session_id' => 'Test Document UUID'
));

$context = stream_context_create(array(
    'http' => array(
        'method' => 'POST',
        'header' => array(
            'Content-Type: application/json',
            'Content-Length: ' . strlen($postdata)
        ),
        'content' => $postdata
    )
));

$response = file_get_contents($url, false, $context);
$responseData = json_decode($response, TRUE);
echo $response;
Example response application/json
{
  "edits": [
    {
      "start": 0,
      "end": 4,
      "replacement": "Let's",
      "sentence": "Lets get started!",
      "error_type": "R:OTHER"
    }
  ]
}

Each edit identifies the source range and replacement text. Preserve the original offsets when applying more than one edit.

About PHP

PHP is a popular scripting language for the web. It is typically processed on a web server as a module, daemon or CGI executable. Many popular web services are written in PHP including well-known websites such as Facebook and frameworks like Wordpress.