PHP code example of kafkiansky / textru

1. Go to this page and download the library: Download kafkiansky/textru library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kafkiansky / textru example snippets





declare(strict_types=1);

backUrl;
use Kafkiansky\Textru\Model\QueuedText;
use Kafkiansky\Textru\Model\Text;
use Kafkiansky\Textru\Model\UserKey;
use Kafkiansky\Textru\ReadModel\QueuedTextResponse;
use Kafkiansky\Textru\TextruInteractor;
use Kafkiansky\Textru\Model\ResultFor;
use GuzzleHttp\Client;
use Kafkiansky\Textru\Model\JsonVisible;
use Kafkiansky\Textru\ReadModel\CheckedResult;

$userKey = 'userKeyFromTextRuApi';

$interactor = new TextruInteractor(new Client(), new UserKey($userKey));

/** @var QueuedTextResponse $queuedTextResponse */
$queuedTextResponse = $interactor->sendForVerification(new QueuedText(new Text('your_text'), new CallbackUrl('your_url')));

$textUid =  $queuedTextResponse->getTextUid();

echo $textUid;  // 48934969




/** @var \Kafkiansky\Textru\ReadModel\CheckedResult $checkedResult */
$checkedResult = $interactor->getResultFor(new ResultFor($textUid, JsonVisible::detail()));

var_dump($checkedResult->getDateCheck()); // DateTimeImmutable object

echo $checkedResult->getUnique(); // 0.00

print_r($checkedResult->getUrls()); // plagiat urls

echo $checkedResult->getCountCharsWithoutSpace(); // 327

echo $checkedResult->getCountCharsWithSpace(); // 383

echo $checkedResult->getCountWords(); // 122

echo $checkedResult->getSpamPercent(); // 15

echo $checkedResult->getWaterPercent(); // 41

# Text.ru return result after time (10-30 m), not immediately.
# To check that result exist, simple use isChecked() method of $checkedResult object, e.g:

if ($checkedResult->isChecked()) {
    // store in database
}





echo $interactor->getRemainingChars(); // 4444