-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcorrection.php
More file actions
33 lines (30 loc) · 956 Bytes
/
correction.php
File metadata and controls
33 lines (30 loc) · 956 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
// Get the text from the request
$text = $_POST['text'];
// Use the LanguageTool API to correct the text
$apiUrl = 'https://api.languagetoolplus.com/v2/check';
$apiKey = 'YOUR_API_KEY';
$data = array(
'text' => $text,
'language' => 'en-US'
);
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\nAuthorization: Bearer " . $apiKey,
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($apiUrl, false, $context);
if ($result === FALSE) { /* Handle error */ }
$response = json_decode($result, true);
// Extract the corrected text from the response
$correctedText = '';
foreach ($response['matches'] as $match) {
$correctedText .= $match['replacements'][0]['value'] . ' ';
}
$correctedText .= substr($text, strrpos($text, ' '));
// Send the corrected text back to the client
echo $correctedText;
?>