1

我正在尝试使用单选按钮来区分用户想要运行的 php 函数。然而什么都没有发生??我认为这是一件小事,但我看不出哪里出错了。

提交表格

value="<?php
if (isset($_GET['searchText']))
 {
 echo($_GET['searchText']);
}

?>"
/>         
<table width="300">
<tr>
<td><label>
<input name="searchType" type="radio"  value="1" id="searchType_0" checked="checked"/>
Aggregated</label></td>

<td><label>
<input name="searchType" type="radio"  value="2" id="searchType_1" />
NonAggregated</label></td>
</tr>
</table>


<input type="submit" value="Search!" name="submit" id="searchButton" />
 </form>

结果页面

<?php
require('code.php'); 
$result = $_GET['searchText'];
$selected_radiobtn = $_GET['searchType'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

    <head>
        <meta http-equiv="content-type" content="text/html;charset=utf-8" />
        <title>Your Website</title>
    </head>

    <body>
        <?
        if ($selected_radiobtn == '1') 
        {
        query($result);
        }           
        elseif($selected_radiobtn == '2') 
        {
        query($result);
        }
         ?> 
    </body>

</html>

代码.php

$searchText=$_GET['searchText'];
function query($searchText)
{
$searchText = bingSpellCheck($searchText);
$searchText = commonPreProcessing($searchText);
}
    function bingSpellCheck($query) {

        $bingArray = array();

        $accountKey = '****************************************';
        $ServiceRootURL = 'https://api.datamarket.azure.com/Bing/Search/';
        $WebSearchURL = $ServiceRootURL.'SpellingSuggestions?$format=json&Query=';

        $cred = sprintf('Authorization: Basic %s', base64_encode($accountKey.":".$accountKey));

        $request = $WebSearchURL.'%27'.urlencode($query).'%27&$top=2';

        $ch = curl_init($request);
        curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
        curl_setopt($ch, CURLOPT_USERPWD, $accountKey.":".$accountKey);
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);//how long before time out
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);//return raw data
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);// dont verify ssl


        $data = curl_exec($ch);
        //$erno = curl_errno($ch);
        //$err = curl_error($ch);


     $js = json_decode($data);

       if($length = count($js->d->results))
       {
               for($i = 0; $i <= $length; $i++)
               {

                       $bingArray[$i]['Value'] = $js->d->results[$i]->Value;

                       if(isset($bingArray[$i]['Value']))
                       {
                               print_r("Did You Mean ".'<a href="?searchText='.$bingArray[$i]['Value'].'">'.$bingArray[$i]['Value']."</a>?");
                               //$searchText = $bingArray[0]['Value'];
                               return $query;
                       }
               }
       }
       else
       { //$searchText = $query;
       //thesaurusPreProcessing($query);
               return $query;
       }

}

unction commonPreProcessing($searchText) {

    $punctuation = array("+",",",".","-","'","\"","&","!","?",":",";","#","~","=","/","$","£","^","(",")","_","<",">");
    $searchText = str_replace($punctuation, ' ', strtolower($searchText));


    for($tokens=array(), $nextToken=strtok($searchText, ' '); $nextToken!==false; $nextToken=strtok(' '))
    {

        if ($nextToken === 'not')
        {
        $nextToken = str_replace('not','NOT',$nextToken);
        }
        if ($nextToken === 'and')
        {
        $nextToken = str_replace('and','AND',$nextToken);
        }
        if ($nextToken === 'or')
        {
        $nextToken = str_replace('or','OR',$nextToken);
        }

        $tokens[] = $nextToken;

    } 

    $array = $tokens;
    $searchText = implode(" ", $array);
    //print_r($searchText);
    $searchText = str_replace(" ","%20",$searchText);

    return $searchText;
    }

任何帮助将非常感激。

4

1 回答 1

0

如果您的表单提交方法是 GET 那么这将起作用

$result = $_GET['searchText'];

或者如果您使用的是 POST,则使用

$result = $_POST['searchText'];

在您的结果页面中

休息一下,我找不到您的代码有任何问题。

于 2012-07-23T04:51:25.990 回答