2

我必须读取文件名中带有单引号 ( ') 的文件的内容。我对文件名没有影响,所以重命名不是一种选择。不幸的是,简单地逃避它是行不通的,例如:

    $myFile = 'John\\\'s file';
    $text = file_get_contents($myFile);

在 Linux 系统上以 PHP 5 访问此文件的正确方法是什么?

4

1 回答 1

1

你不需要双重转义你的字符串:

$myFile = 'John\'s file'; // This works fine.
$text = file_get_contents($myFile);

我刚刚在我的终端上尝试了一个类似的命令:

php -r "chdir('te\'st');"

有用。

于 2016-12-28T10:29:28.197 回答