在 php 中使用牛津词典 API 时出错

嘿,你自己不认识的朋友 Amaan,我正在为我的项目使用牛津词典 API,但我遇到了错误。这是我的代码


<?php


include_once 'dictionary.class.php';



$dictionary = new Dictionary("APP ID", "APP KEY", "en-gb");



$dictionary->newDictionaryRequest("Pizza");



$dictionary->setResult(0);



echo "<h1>Dictionary Class Results - ".$dictionary->word."</h1> - status: ".$dictionary->errors['status'];

echo "<b>Word:</b> ".$dictionary->word;

echo "<br><b>Definition:</b> ".$dictionary->getDefinition();

echo "<br><b>Short Definition:</b> ".$dictionary->getShortDefinition();

echo "<br><b>Example:</b> ".$dictionary->getExample(0);

echo "<br><b>Example 2:</b> ".$dictionary->getExample(1);

echo "<br><b>Lexical:</b> ".$dictionary->getLexical();

echo "<br><b>Phonetic:</b> ".$dictionary->getPhonetic();

echo "<br><b>Origin:</b> ".$dictionary->getOrigin();

echo "<br><b>Language:</b> ".$dictionary->API_LANG;

echo "<br><b>Audio:</b> <audio controls><source src='".$dictionary->getAudio()."' type='audio/mpeg'>Your browser does not support HTML audio</audio><br>";


echo "<br></br>Using result set: <b>".$dictionary->selected_result."</b>";

echo "<br></br>Total result sets available from request: <b>".$dictionary->num_returned_results."</b>";



?>

错误是这样的:-致命错误:未捕获的错误:调用此行上未定义的方法 Dictionary::setResult() :- $dictionary->setResult(0);


这是dictionary.class.php的链接


繁星淼淼
浏览 76回答 1
1回答

慕尼黑的夜晚无繁华

解决了如果您在此行中也遇到错误&nbsp;$dictionary->setResult(0);答案是:删除此行$dictionary->setResult(0);。为什么 :此行是可选的,如果您想要多个结果集,请使用此行,否则从代码中删除此行。选择 :如果结果集不超过一组,则显示一条消息。建议 :仔细阅读Readme.md文件。特别感谢@kerbholz谢谢你。
打开App,查看更多内容
随时随地看视频慕课网APP