function phpGrep($q, $path)
{
    $ret = array();
    $fp = opendir($path);
    while ($f = readdir($fp)) {
        if (preg_match("#^\\.+\$#", $f)) {
            continue;
        }
        // ignore symbolic links
        $file_full_path = $path . DS . $f;
        if (is_dir($file_full_path)) {
            $ret = array_unique(array_merge($ret, phpGrep($q, $file_full_path)));
        } else {
            if (stristr(file_get_contents($file_full_path), $q)) {
                $ret[] = $file_full_path;
            }
        }
    }
    return $ret;
}
 function phpGrep($q, $path, $base)
 {
     $fp = opendir($path);
     global $t, $r, $ICEcoder, $serverType, $selectedFiles, $docRoot, $ICEcoderDir, $context;
     if (!isset($ret)) {
         $ret = "";
     }
     $slash = $serverType == strpos($path, "\\") > -1 ? "\\" : "/";
     while ($f = readdir($fp)) {
         if (preg_match("#^\\.+\$#", $f)) {
             continue;
         }
         $fullPath = $path . $slash . $f;
         if (is_dir($fullPath)) {
             $ret .= phpGrep($q, $fullPath, $base);
         } else {
             if (stristr(toUTF8noBOM(file_get_contents($fullPath, false, $context), false), $q)) {
                 $bFile = false;
                 $foundInSelFile = false;
                 // Exclude banned files
                 for ($i = 0; $i < count($ICEcoder['bannedFiles']); $i++) {
                     if (strpos($f, $ICEcoder['bannedFiles'][$i]) !== false) {
                         $bFile = true;
                     }
                 }
                 // Exclude the folder ICEcoder is running from
                 $rootPrefix = '/' . str_replace("/", "\\/", preg_quote(str_replace("\\", "/", $docRoot))) . '/';
                 $localPath = preg_replace($rootPrefix, '', $fullPath, 1);
                 if (strpos($localPath, $ICEcoderDir) === 0) {
                     $bFile = true;
                 }
                 $findPath = str_replace($base, "", $fullPath);
                 for ($i = 0; $i < count($selectedFiles); $i++) {
                     $stringExtra = $selectedFiles[$i] != "|" ? "/" : "";
                     if (strpos($findPath . $stringExtra, str_replace("|", "/", $selectedFiles[$i]) . $stringExtra) === 0) {
                         $foundInSelFile = true;
                     }
                 }
                 if (!$bFile && (count($selectedFiles) == 0 || count($selectedFiles) > 0 && $foundInSelFile)) {
                     $ret .= "<a href=\\\"javascript:top.ICEcoder.openFile('" . $fullPath . "');top.ICEcoder.goFindAfterOpenInt = setInterval(function(){goFindAfterOpen('" . $fullPath . "')},20);top.ICEcoder.showHide('hide',top.get('blackMask'))\\\">";
                     $ret .= str_replace($base, "", $fullPath) . "</a><div id=\\\"foundCount" . $r . "\\\">" . $t['Found'] . " " . substr_count(strtolower(toUTF8noBOM(file_get_contents($fullPath, false, $context), false)), $q) . " " . $t['times'] . "</div>";
                     if (isset($_GET['replace'])) {
                         $ret .= "<div class=\\\"replace\\\" id=\\\"replace\\\" onClick=\\\"replaceInFileSingle('" . $fullPath . "');this.style.display=\\'none\\'\\\">" . $t['replace'] . "</div>";
                     }
                     $ret .= '<hr>';
                     echo 'foundArray.push("' . $fullPath . '");' . PHP_EOL;
                     $r++;
                 }
             }
         }
     }
     return $ret;
 }