如何使php字符串可用于html查询


How to make the php strings selectable for the html query?

我希望将字典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++;
        }
    }
 }

"Quick bug,在$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>';