Glob is not working when directory name with special characters like square brackets “[ ]”

前端 未结 4 1389
长发绾君心
长发绾君心 2021-01-13 01:47

I have issue while using glob function when path directory with square brackets.

// Example 1 - working
$path = \'temp\'. DIRECTORY_SEPARATOR .\'dir - name\'         


        
4条回答
  •  旧巷少年郎
    2021-01-13 02:01

    Try

    $path = 'temp'. DIRECTORY_SEPARATOR .'dir - [name]';
    $from = array('[',']');
    $to   = array('\[','\]');
    $files =glob(str_replace($from,$to,$path . "\\*.txt"));
    echo '
    ';
        print_r($files);
    echo '
    ';

提交回复
热议问题