自动完成不建议大写字母输入PHP和XML

时间:2012-04-01 03:45:45

标签: php autocomplete

我正在创建一个简单的表单,在这种形式中,我想要一个自动完成功能。 http://www.script-tutorials.com/autocomplete-with-php-jquery-mysql-and-xml/我阅读了本教程,对于我的数据,我使用以下格式创建了一个XML文件,

<inputs>
    <input>AA</input>
    <input>BAC</input>
    <input>AWT</input>
    <input>tag</input>
    <input>AHY</input>
</inputs>

处理自动完成的方法是

 $aValues = $aIndexes = array();
        $sFileData = file_get_contents('data2.xml'); // reading file content
        $oXmlParser = xml_parser_create('UTF-8');
        xml_parse_into_struct($oXmlParser, $sFileData, $aValues, $aIndexes);
        xml_parser_free( $oXmlParser );

        $aTagIndexes = $aIndexes['ITEM'];
        if (count($aTagIndexes) <= 0) exit;
        foreach($aTagIndexes as $iTagIndex) {
            $sValue = $aValues[$iTagIndex]['value'];
            if (strpos($sValue, $sParam) !== false) {
                echo $sValue . "\n";
            }
        }
    break;

但问题是,当我在字段中输入时,它总是建议小写的数据。例如,如果我输入'A'或'a',它只会建议数据'tag'

问题是什么,我该如何解决?

感谢。

1 个答案:

答案 0 :(得分:4)

strpos()函数区分大小写,因此它只返回包含字母“a”的“tag”。如果您想要不区分大小写的检查,则应使用stripos()