grep for RegEx递归遍历目录

时间:2014-07-24 07:41:52

标签: php regex recursion grep

在我的PHP文件中,我想使用grep在directorystructur中搜索递归。 搜索目录和主机名由变量给出。 ($ path和$ _POST ['host_select']) 我试过这个:

<?PHP
function read_hostfile()
{
$path = '/omd/sites/test/etc/icinga/conf.d/objects';
$string= $_POST['host_select'];
$shellcommand = "grep -E -r -i --include=*cfg 'host_name*switch' $path";
$result = exec($shellcommand);
$hostfile = file($result);
.
.
?>

我尝试按如下方式编辑我的grep-command:

$shellCommand = "grep -E -d=read -r --include='cfg host_name*$string' $path";

我收到了file()的错误:

execgrep: unknown directories method
file()PHP Warning:  file(): Filename cannot be empty in /home/thomas/configpage_icinga_test/test.php on line 14

1 个答案:

答案 0 :(得分:0)

*之前和之后您不需要pattern

试试这个:

$shellcommand = "grep -E -r -i --include='cfg host_name.*switch' $path";