0

我的目的是$suggestion[$ss_count]成为一个超链接,引导您到 index2.php 并将$suggestion[$ss_count]in 插入到查询字段中。由于我的查询是通过邮寄方式发送的,我该怎么做?

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 ('<h2>Spelling suggestions</h2>');
    while ($ss_count <=$s_count)
    {
    echo ($suggestion[$ss_count].'<br>');
    $ss_count++;
    }

 }

HTML:

<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Search Attempt</title>
</head>
<body>
<form method="POST" action='safegoogle.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>
4

1 回答 1

0

我认为如果您只是将 php 代码和 html 放入一个文件并让您的表单发布到它自己会更容易......这样您的 php 变量将可以从文件中的任何位置访问......并且您可以现在智能地混合代码和标记来实现你想要的。

于 2013-07-16T17:16:07.967 回答