abc
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Suggestions</title>
<script type="text/javascript">
function suggest(f) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if(this.readyState == 4 && this.status == 200){
document.getElementById('show').innerHTML = this.responseText;
}
}
xhr.open('GET', "suggest.php?f="+f, true);
xhr.send();
// xhr.open('POST', "suggest.php");
// xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
// xhr.send("f"+f);
}
</script>
</head>
<body>
Search : <input type="text" name="search" id="search" onkeyup = "suggest(this.value)"><br><br>
<div id="show"></div>
</body>
</html>
suggest.php
<?php
$s = $_GET['f'];
$a = array("Programming in php", "Language of scripting", "Programming in C", "Programming in java", "Programming in HTML");
$str = "";
foreach($a as $val){
if(preg_match("/^$s/i", $val)){
$str .= $val."<br>";
}
}
if($str === "") {
echo "Not found in the array";
}
else {
echo $str;
}
?>