Beispiel #1
0
        while ($j > -1 && $pattern[$i] != $pattern[$j]) {
            $j = $nextTable[$j];
        }
        $nextTable[++$i] = ++$j;
    }
}
function MorrisPratt($text, $pattern)
{
    $n = strlen($text);
    $m = strlen($pattern);
    $nextTable = array();
    preprocessMorrisPratt($pattern, $nextTable);
    $i = $j = 0;
    while ($j < $n) {
        while ($i > -1 && $pattern[$i] != $text[$j]) {
            $i = $nextTable[$i];
        }
        $i++;
        $j++;
        if ($i >= $m) {
            return $j - $i;
        }
    }
    return -1;
}
$flag = MorrisPratt($text, $pattern);
if ($flag >= 0) {
    echo '<br><br><h1 style="text-align:center">' . "True";
} else {
    echo '<br><br><h1 style="text-align:center">' . "False";
}
$data = array('http' => array('request_fulluri' => true, 'ignore_errors' => true, 'header' => "Authorization: Basic {$auth}"));
$context = stream_context_create($data);
// Get the response from Bing.
$response = file_get_contents($requestUri, 0, $context);
// Decode the response.
$jsonObj = json_decode($response);
$c = 0;
echo "<p>{$pattern}</p><br/><br/> Above Text is present on the pages<br/>";
foreach ($jsonObj->d->results as $value) {
    $c++;
    if ($c == 4) {
        break;
    }
    $curl = curl_init();
    curl_setopt_array($curl, array(CURLOPT_RETURNTRANSFER => 1, CURLOPT_URL => $value->Url, CURLOPT_USERAGENT => 'Codular Sample cURL Request'));
    // Send the request & save response to $resp
    $text = str_ireplace(array(" a ", " the ", " an "), "", strtolower(strip_tags(curl_exec($curl))));
    // Close request to clear up some resources
    curl_close($curl);
    $temp = MorrisPratt($text, $pattern);
    if ($temp > 0) {
        echo "<a href='{$value->Url}'>{$value->Title}</a><br/>";
    }
}
$time_end = microtime(true);
//dividing with 60 will give the execution time in minutes other wise seconds
$execution_time = ($time_end - $time_start) / 60;
//execution time of the script
echo '<br/><b>Total Execution Time:</b> ' . $execution_time . ' Mins';
?>
</div>