grammarbot / grammarbot-php-client
关于此包的最新版本(dev-master)没有提供任何许可信息。
这是一个用于使用Grammarbot API解析文本语法和语法错误的PHP客户端。
dev-master
2018-12-13 22:55 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-29 05:28:04 UTC
README
这是一个用PHP编写的HTTP客户端包装器,用于利用Grammarbot.io API。它简单直接。可以使用composer或手动安装。
安装
使用Composer
在你的项目目录中依次运行以下命令
git clone https://github.com/imranswe/grammarbot-php-client.git
composer install
或者只运行以下命令
composer require grammarbot/grammarbot-php-client:dev-master
手动安装
下载仓库代码,并在你的代码中直接引入GrammarBot.php文件
<?php
require_once dirname(__FILE__). '/src/GrammarBot/GrammarBot.php';
use GrammarBot\GrammarBot;
$text = 'A quick brown fox jummp over the lazzy dog';
/*Usage # 1 is using all defaults */
$grammarbot = new GrammarBot();
//call the api
$json = $grammarbot->check($text);
$matches = $json->matches;
foreach($matches as $match){
echo $match->message. "<br>";
echo $match->offset. "<br>";
echo $match->length. "<br>";
echo $match->context->text. "<br>";
echo $match->rule->id. "<br>";
echo $match->rule->description. "<br>";
echo $match->rule->issueType. "<br>";
echo $match->rule->category->id. "<br>";
echo $match->rule->category->name. "<br>";
}
首次使用
此示例使用所有默认设置
<?php
require_once dirname(__FILE__). '/vendor/autoload.php';
use GrammarBot\GrammarBot;
$text = 'A quick brown fox jummp over the lazzy dog';
/*Usage # 1 is using all defaults */
$grammarbot = new GrammarBot();
//call the api
$json = $grammarbot->check($text);
$matches = $json->matches;
foreach($matches as $match){
echo $match->message. "<br>";
echo $match->offset. "<br>";
echo $match->length. "<br>";
echo $match->context->text. "<br>";
echo $match->rule->id. "<br>";
echo $match->rule->description. "<br>";
echo $match->rule->issueType. "<br>";
echo $match->rule->category->id. "<br>";
echo $match->rule->category->name. "<br>";
}
第二次使用
此示例覆盖默认设置
<?php
require_once dirname(__FILE__). '/vendor/autoload.php';
use GrammarBot\GrammarBot;
$base_uri = 'http://api.grammarbot.io/v2';
$endpoint = '/check';
$lang = 'en-US';
$api_key = 'yourOwnAPIKEY';
$text = 'A quick brown fox jump over the lazzy dog';
//Usage # 2 is overriding using constructor
$grammarbot = new GrammarBot($base_uri, $endpoint, $api_key, $lang);
//call the api
$json = $grammarbot->check($text);
$matches = $json->matches;
foreach($matches as $match){
echo $match->message. "<br>";
echo $match->offset. "<br>";
echo $match->length. "<br>";
echo $match->context->text. "<br>";
echo $match->rule->id. "<br>";
echo $match->rule->description. "<br>";
echo $match->rule->issueType. "<br>";
echo $match->rule->category->id. "<br>";
echo $match->rule->category->name. "<br>";
}