orzcc / oxfordapi-wrapper
牛津词典API的PHP/Laravel包装器
1.2.2
2022-01-14 09:07 UTC
Requires
- guzzlehttp/guzzle: ^7.0.1
README
牛津词典API的PHP/Laravel包装器
安装
首先,通过Composer安装此包。
composer require inani/oxfordapi-wrapper
然后,在config/app.php中包含服务提供者。
'providers' => [ ... Inani\OxfordApiWrapper\OxfordWrapperServiceProvider::class, ... ];
至少在env文件中设置
OXFORD_API_BASE_URI = OXFORD_APP_ID = OXFORD_APP_KEY =
创建一个新的实例
// Make it or pass it as argument $oxford = app(Inani\OxfordApiWrapper\OxfordWrapper::class);
如何使用
翻译
// look for the translation from a language to an other, returns a parser $parser =$oxford->lookFor('balablabla') ->from('en') ->to('es') ->translate(); // get array of translations $translations = $parser->get(); // get array of [example => [translations]] $examples = $parser->getExamples();
定义
// look for the definitions of a word, returns a parser $parser =$oxford->lookFor('balablabla') ->define(); // get array of definitions $definitions = $parser->get();
示例
// look for the examples of a word, returns a parser $parser =$oxford->lookFor('balablabla') ->examples(); // get array of examples $definitions = $parser->get();
同义词词典
// You can try all combinations $res = $oxford->lookFor('happy') ->synonym() ->antonym() ->fetch(); // results will be related to (syno or anto) // get synonyms and/or antonyms $res->get(); // get only antonyms or null if not specfied in fetch $res->antonyms(); //get only synonyms or null if not specfied in fetch $res->synonyms();
发音
$res = $oxford->lookFor('ace') ->talk(); // get the array of result $res->get(); // get the link to the audio file of pronunciation $res->speak(); //get the spelling $res->spell(); //get the notation $res->notation();