Help to write a function that will display a list of files from the directory that contain the search word. Directory and search word are set as function parameters.
- Show what you did for this. - user207618
|
1 answer
function f($dir, $name, $exclude_dir = true) { return array_filter(scandir($dir), function ($i) use ($exclude_dir, $name) { if ($exclude_dir && is_dir($i)) return false; return substr_count($i, $name); } );} - 0xdef, did you check the function of the function or not? It just gives me an error: Parse error: syntax error, unexpected '$ exclude_dir' ... - Eugene
- Pull request:
function () use $exclude_dir {=>function ($e) use ($exclude_dir, $name) {;substr_count($dir, $name)=>substr_count($e, $name). - user207618 - Earned, but the list of found files does not display. You need to either print_r the result in <pre> </ pre> tags, or implant the result and list it out ... This will add a couple of lines of code. But then all the ingenuity and complexity of the function is superfluous. Can it somehow be easier to list the files found? - Eugene
- Are you kidding me? The file list function returns in an array. You can withdraw it as you wish, in any convenient way. - 0xdef
- @Eugene, dear, you already and TK rivet ??? - user207618
|