我在使用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'
}