<?php

$matches 
= array();
$fs "";

if (isset(
$_GET['s'])) {
    
$s explode(" "$fs $_GET['s']);
    
$d opendir(".");

    while (
$file readdir($d)) {
        if (
is_file($file)) {
            
// Fetch and prepare the file contents
            
$f file_get_contents($file);
            
$f str_ireplace(
                array(
"<?""<?php""?".">"),
                
"",
                
$f
            
);
            
$f strip_tags($f);

            
// Search for the terms
            
foreach ($s as $term) {
                if (
$m stristr($f$term)) {
                    
$m substr($m0strlen($term) + 20);
                    
$m sprintf("%-'.30s"$m);
                    
$m preg_replace(
                        
"/(" implode("|"$s) . ")/i"
                        
"<span style='font-weight:bold'>$1</span>",
                        
$m
                    
);
                    
$matches[] = "(<a href='$file'>$file</a>) " $m;
                }
            }
        }
    }
    
closedir($d);
}

?>
<html>
<head>
    <title> <?= basename($_SERVER['PHP_SELF']) ?> </title>
</head>

<body>
    <form action="<?= $_SERVER['PHP_SELF'?>" method="get">
        Search terms: <input type="text" name="s" value="<?= $fs ?>" />
        <input type="submit" />
    </form>
    <hr />
    <?= implode("<hr />"$matches?>
</body>
</html>