我有一个根路径,可以在文件中定义,在这个路径中:
define('FILE_ROOT', dirname( __FILE__ ) )
This can get an output of D:'xampp'htdocs'library'includes'templates
在这个模板目录下,有一个文件夹,它的相对路径在另一个软件中定义:
$file_short_path = 'USERS_DATA/';
现在,我想要得到完整的路径。我试着:
$file_full_path = FILE_ROOT . $file_short_path
the result is D:'xampp'htdocs'library'includes'templatesUSERS_DATA/
如果我在FILE_ROOT后面加上'/',它会变成一个错误的路径:
$file_full_path = FILE_ROOT . '/' . $file_short_path
D:'xampp'htdocs'library'includes'templates/USERS_DATA/
如果我添加''',我得到语法错误:
$file_full_path = FILE_ROOT . ''' . $file_short_path
如何获得正确的file_full_path?
您需要转义'
。'
可以添加两次。
$file_full_path = FILE_ROOT . '''' . $file_short_path