0

我希望将 Dictionary API 给出的建议变成可以查询或直接插入到文本中的链接,然后再搜索它们。无论如何,我都希望实现某种查询扩展。

 <!DOCTYPE html>
 <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Search Attempt</title>
    </head>
    <body>
    <form method="POST" action='AllinOneMonstaaa.php'>
    <label for="query">Query</label><br/>
    <input name="query" type="text" size="60" maxlength="60" value="" /><br /><br /> 
    <select name ="agg">
    <option value="Aggregated">Aggregated</option>
    <option value="Non-Aggregated">Non-Aggregated</option>
    <option value="Bing">Bing</option>
    <option value="Blekko">Blekko</option>
    <option value="Faroo">Faroo</option>
    </select>
    <input name="bt_search" type="submit" value="Search" /> </form>
    <h2> Results </h2>
    </body>
</html>

 <?php
 if ($_POST['query'])

 {
    $query = urlencode($_POST['query']);
    $s_count = 0;
    $ss_count = 0;
    $query = 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/'.$query.'? 
    $xml = new SimpleXMLIterator(file_get_contents($query));
    foreach ($xml -> suggestion as $suggestion[$s_count])
    {
        $s_count++;
    }
    if ($s_count > 1)
    {
        echo ('<h4>Did you mean?</h4>');
        while ($ss_count <=$s_count)
        {
         echo ($suggestion[$ss_count].'<br>');
         $ss_count++;
        }

    }
 }
4

1 回答 1

0

'快速错误,$query 行上缺少 '。

echo '<a href="whatever">'. $suggestion[$ss_count].'<br>';

编辑:这会将他们发送到 Dictionary.com,并带有要在那里查找的单词。除此之外,我不知道您将如何制定网址。

echo '<a href="http://dictionary.reference.com/browse/"' . $suggestion[$ss_count] . '" target="_new">' . $suggestion[$ss_count] . '<br>';
于 2013-07-17T13:41:31.933 回答