I am trying to search and check for the duplicate details that is available in the database using php.The user enters several names and then a phone number to check for the duplicates. Below is my function. I just cropped out some parts because it was too long.
function gtc($names,$phone)
{
$pageNumb=20;
$position = array(5);
$sepname=explode(",","$names");
foreach ($sepname as $sepname1)
{
for ($page=0;$page<=$pageNumb;$page=$page + 1)
{
$turl="http://192.168.111.2119/search.php?qry=$sepname1&page=$page";
$search=curl_init();
curl_setopt($search,CURLOPT_URL,$turl);
curl_setopt($search,CURLOPT_RETURNTRANSFER,1);
curl_setopt($search,CURLOPT_FAILONERROR,true);
curl_setopt($search,CURLOPT_AUTOREFERER,true);
$result=curl_exec($search);
$dom = new DOMDocument();
@$dom->loadHTML($result);
$xpath=new DOMXPath($dom);
$elements = $xpath->evaluate("//div[@id='inf']");
foreach ($elements as $element)
{
$position[$sepname1] = $position[$sepname1] + 1;
foreach($position as $key=>$val)
$contct = $element->getElementsByTagName("contact")->item(0)->nodeValue;
if (preg_match("/$phone/i",$contct)) {
echo "Found In Database>";
}
}
ob_flush();
flush();
}
}
}
?>
The function works perfectly but the only problem that I am having is although a match is found it goes until the last page which is given in the for loop and then goes through the next name. I would like to know is it possible to make when a match is found stop processing and then search for the next name?
I don’t want to use exit(); because it completely stops the execution
The input format is as below
User inputs names: john, Sam, Michael, Steve
Phone number:0084554741
Any help will be appreciated