dongliyu3278 2013-02-06 01:17
浏览 28
已采纳

Strtoupper()PHP用于混合字符串

I've been working on a project for school where I have you search for a string, and it wil query a database and return all of the words which are in that string of letters. For that, I have to use strtoupper(), which works fine if you have a string of all uppercase or lowercase letters. If you enter AAB or aab into the search, everything will work fine, and it will return the two anagrams, ABA and BAA. However, if you type in aAB, it will return nothing. So it is getting the post data from the input, named alpha, and then it is alphabetizing the word, so if you typed in ABA, it would return AAB, and then making it uppercase.

<title>Scrabble</title>
<?php
require 'connect.inc.php';
if (isset($_POST['al'])){
    $al=$_POST['al'];
    $al=alpha($al);
    $al=trim(strtoupper($al));
    $query="SELECT * from Words WHERE alpha='$al'";
    if ($query_run = mysql_query($query)){

        while ($query_row = mysql_fetch_assoc($query_run)){
            $alpha = $query_row['alpha'];
            $ana = $query_row['word'];

            echo "<strong>$ana</strong> $alpha<br>";

        }
    }


}
function alpha($word){
    $array=array();
    for($x=0;$x<strlen($word);$x++){
        $char=substr($word,$x,1);
        $array[$x]=$char;


    }
    sort($array);
    $alpha=implode('',$array);
    return $alpha;

}
?>
<form action='scrabble.php' method='POST'>
Enter text to anagram. Please use either all uppercase or all lowercase<input type='text'                   name='al'>
<input type='submit'>
</form>

he link is here http://newdev.shodor.org/~amalani/newdev/scrabble.php Thanks

  • 写回答

1条回答 默认 最新

  • dongnuoyi8833 2013-02-06 01:40
    关注

    Multiple issues:

    PHP's sort function returns a boolean for whether it was successful or not. In your code you have:

    $array=sort($array);
    

    When it should just be:

    sort($array);
    

    You have a syntax error near the top:

    $alphagram=trim(strtoupper($al);
    

    Should probably be:

    $alphagram = trim(strtoupper($alphagram));
    

    I also noticed that on your website, you use:

    name='al'
    

    And then in the script try to access the POST variable alpha. You should be using:

    $_POST['al']
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里