i have below mentioned search code for keyword from given pages in the $pages array variable, it is working as i want, but it taking so much time to load because there are multiple pages in $pages array. how to increase this speed? please let me know.
<?php
$match="";
if(isset($_POST['submit'])){
if(isset($_POST['txt_search'])){
$match=trim($_POST['txt_search']);
}
if($match==""){
print "Please enter search text";exit;
}
}
<html>
<body>
<form action="" method="post">
<input type="text" name="txt_search" placeholder="Search term"/>
<input type="submit" value="Search" name="submit" onClick=""/>
</form>
<p id="text">
<?php if($match!=""){
mastersearch($match);
}?>
</p>
</body>
</html>
<?php
function mastersearch($match) {
$pages=array("index.php","about.php","contact.php","books.php","careers.php","shopping.php","travels.php","lifestyle.php","movies.php","museum.php");
foreach ($pages as $value) {
$text=$value;
$path="http://sitename.com/user/";
$value = $path.$value;
$json = file_get_contents($value);
$lastPos=0;
$last=strripos($json, $match);
while (($lastPos = stripos($json, $match, $lastPos))!== false) {
$positions[] = $lastPos;
preg_match("/<title>(.*)<\/title>/i", $json, $title);
print $title[1];
print "<br><a href='$value'>$text</a><br/>";
$lastPos = $lastPos + strlen($match);
}
}
}
?>