I’m creating a simple form and in this form I want to have an autocomplete functionality. http://www.script-tutorials.com/autocomplete-with-php-jquery-mysql-and-xml/ I read this tutorial, and for my data I created an XML file with the following format,
<inputs>
<input>AA</input>
<input>BAC</input>
<input>AWT</input>
<input>tag</input>
<input>AHY</input>
</inputs>
And the method which handles the autocomplete is
$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;
But the problem is, when I’m typing into the field, it always suggest the data which is lowercase. For example if I type either ‘A’ or ‘a’ it only suggest the data ‘tag’
What is the problem, how should I solve this ?
Thanks.
The
strpos()function is case sensitive, so it will only return “tag” as containing the letter “a”. You should usestripos()if you want a case-insensitive check.