从preg_replace发送匹配到函数内的scandir

时间:2014-03-04 18:49:22

标签: php preg-replace scandir

我在使用scandir时遇到问题,该变量通过preg_replace中的函数发送变量。我在运行代码PHP Warning: scandir(../dir/$1): failed to open dir: No such file or directory时收到警告,然而,当我回显$dir时,它正确地回应它,并将$ 1扩展为变量。这是我的代码:

$str = preg_replace('/([0-9]{2})/', $this->functionName("$1"), $str);

private function functionName($year) {
        $path = '../dir/'.$year;
        echo $path; // echos 'dir/14'
        $results = scandir($path); // claims $path is 'dir/$1'
}

0 个答案:

没有答案