Esempio n. 1
0
 public function test($function, $testedVersion)
 {
     echo '<tr><td style="width:150px">' . $function;
     echo '</td><td><pre>' . highlightkeyword(print_r($this->{$function}(), TRUE), '=> ' . $testedVersion . "\n") . '</pre></tr></tr>';
 }
function highlightkeyword($str, $search)
{
    $occurrences = substr_count(strtolower($str), strtolower($search));
    $newstring = $str;
    $match = array();
    for ($i = 0; $i < $occurrences; $i++) {
        $match[$i] = stripos($str, $search, $i);
        $match[$i] = substr($str, $match[$i], strlen($search));
        $newstring = str_replace($match[$i], '[[#]]' . $match[$i] . '[[@]]', strip_tags($newstring));
    }
    $newstring = str_replace('[[#]]', '<strong>', $newstring);
    $newstring = str_replace('[[@]]', '</strong>', $newstring);
    return $newstring;
}
$results_count = 0;
foreach ($demo_data as $demo_item) {
    // fuzzy search
    //if (strlen($search_key) - similar_text(strtolower($demo_item["title"]), $search_key) == 0) {
    // regular strpos search to speed things up a little
    if (stripos($demo_item["title"], $search_key) !== false) {
        echo '<li class="result"><a href="' . $demo_item["link"] . '">' . highlightkeyword($demo_item["title"], $search_key) . '</a></li>';
        $results_count++;
        if ($results_count >= $search_limit) {
            echo '<li class="result view-all"><a href="index.html">All results</a></li>';
            exit;
        }
    }
}
if ($results_count == 0) {
    echo "<li><a>No results where found</a></li>";
}