grep with -f like in PHP

前端 未结 2 1985
终归单人心
终归单人心 2021-01-12 07:09

Is there such a function in PHP that does grep -f filename in unix/linux systems. If there is none, what PHP functions/tools would help in creating a customised method/funct

2条回答
  •  旧时难觅i
    2021-01-12 07:57

    You can combine the file_get_contens() function to open a file and the preg_match_all() function to capture contents using a regex.

    $file = file_get_contents ('path/to/file.ext');
    preg_match_all ('regex_pattern_here', $file, $matches);
    print_r ($matches);
    

提交回复
热议问题