if ($os_name == "unix") {
     // use Unix find and grep
     if ((bool) ini_get('safe_mode')) {
         // have to use PHP functions for find and grep, this is slower
         find($baseDir, $files, '/.*?\\.php$/', $pathSeparator);
         $array = grep($files, "/\\->_\\(\\'.*?\\'\\)/");
     } else {
         // We can use find and grep
         $return = shell_exec("find {$baseDir} -follow -name \"*.php\" -exec grep -o -P \"\\->_\\(\\'.*?\\'\\)\" {} /dev/null \\;");
         $array = preg_split("/{$baseDir}/", $return);
     }
 } else {
     if ($os_name == "windows") {
         // use php functions for find and grep
         find($baseDir, $files, '/.*?\\.php$/', $pathSeparator);
         $array = grep($files, "/\\->_\\(\\'.*?\\'\\)/i");
     }
 }
 $keys = array();
 foreach ($array as $h) {
     preg_match_all("/\\->_\\('(.*?)'\\)/", $h, $matches);
     for ($i = 1; $i < count($matches); $i++) {
         if (count($matches[$i]) > 1) {
             for ($j = 0; $j < count($matches[$i]); $j++) {
                 $keys[$matches[$i][$j]] = "";
             }
         } else {
             if (isset($matches[$i][0])) {
                 $keys[$matches[$i][0]] = "b";
             }
         }
function ContextFind($key,$FileArr = false)
{
	global $ExploreDir, $Path;
	$ret["dirs"] = array();
	$ret["files"] = array();
	
	function grep($file,$key)
	{
		if(is_dir($file))
		{
			exec("grep -rli \"".$key."\" ".$file,$out);
			$out = empty($out) ? false : $out;
			return $out;
		}
		else
		{
			$mimetype = mime_content_type($file);
			$pathinfo = pathinfo($file);
			$mimetype = isset($pathinfo["extension"]) && strtolower($pathinfo["extension"]) == "txt" ? "text/plain" : $mimetype;
			if(!preg_match("/^text/",$mimetype)) return false;
			$cmd = "grep -li \"".$key."\" ".$file;
			return exec($cmd);
		}
	}
	
	if($FileArr)
	{
		foreach ($FileArr["dirs"] as $dir)
		{
			$files = grep($ExploreDir."/".$dir,$key);
			if($files) foreach ($files as $file) $ret["files"][] = str_replace($ExploreDir."/","",$file);
		}
		foreach ($FileArr["files"] as $file)
		{
			if(grep($ExploreDir."/".$file,$key)) $ret["files"][] = str_replace($ExploreDir."/","",$file);
		}
	}
	else
	{
		$Arr = _AllFiles($ExploreDir.'/'.$Path);
		foreach ($Arr as $dir => $files)
		{
			foreach ($files as $file)
			{
				if(grep($dir.$file,$key)) $ret["files"][] = str_replace($ExploreDir."/","",$dir).$file;
			}
		}
	}
	
	return $ret;
}
function edit_xinetd_conf($service)
{
    $xinetd_conf = '/etc/xinetd.conf';
    $contents = unix_nl(rf($xinetd_conf));
    $lines = explode("\n", $contents);
    $j = sizeof($lines);
    for ($i = 0; $i < sizeof($lines); $i++) {
        if (grep($lines[$i], $service, 'w')) {
            $fundstelle_anfang = $i;
            $j = $i;
            $parts = explode($lines[$i], $contents);
        }
        if ($j < sizeof($lines)) {
            if (strstr($lines[$i], '}')) {
                $fundstelle_ende = $i;
                $j = sizeof($lines);
            }
        }
    }
    if (isset($fundstelle_anfang) && isset($fundstelle_ende)) {
        for ($i = $fundstelle_anfang; $i <= $fundstelle_ende; $i++) {
            if (strstr($lines[$i], 'disable')) {
                $disable = explode('=', $lines[$i]);
                $disable[1] = ' yes';
                $lines[$i] = implode('=', $disable);
            }
        }
    }
    $fundstelle_anfang = NULL;
    $fundstelle_ende = NULL;
    $contents = implode("\n", $lines);
    wf($xinetd_conf, $contents);
}
Exemple #4
0
/**
	The most typical grep is for non-null (logically true) elements.
	Here's my chosen shortcut:
*/
function collect($arr)
{
    return grep('id', $arr);
}
Exemple #5
0
        $buff .= $line;
        /*
        	    if (preg_match("/ESSA/i",$line,$var)){	
        	preg_match("(\(-?[0-9]+ C)",$line,$val);
        	echo "<br>TAF: $line";
        	$v = substr($v,1);
        	$v = substr($v,0,3);		
        	$v = intval($v);
        	$temp = $v;
        	
        	#echo $v.'<br>';
        	#@dbq("INSERT INTO weather (dat, temp) VALUES (now(), '$temp')");
        	
        }
        */
    }
}
fclose($fd);
$buff = str_replace("\t", " ", "{$buff}");
$buff = str_replace("  ", " ", "{$buff}");
#$sorted= str_replace("TEMPO", "\nTEMPO", "$sorted");
echo "{$buff}";
function grep($from, $to, $haystack)
{
    $pattern = "#{$from} (.*?){$to}#s";
    if (preg_match($pattern, $haystack, $match)) {
        return $match[0];
    }
}
echo "->" . grep("ESSA", "=", $buff);