【问题标题】:define path that contains variable (php)定义包含变量的路径(php)
【发布时间】:2026-01-29 06:10:02
【问题描述】:

我正在制作图片幻灯片

$article = "This is the title of the slide show images";

现在正在定义路径

// set the absolute path to the directory containing the images
define ("IMGDIR", "./pathsubdir/$article/");

尝试过

define ('IMGDIR', '/articles/" . $article . "/');

不起作用(以上两者)

define ('IMGDIR', '/articles/"This is the title of the slide show images"/');

有效 ^

但是我怎样才能把它作为一个变量让它工作呢?因为 $article 是一个动态值

提前致谢

【问题讨论】:

    标签: php variables constants


    【解决方案1】:

    试试

    define ('IMGDIR', '/articles/' . $article . '/');
    

    如果文章中需要双引号

    define ('IMGDIR', '/articles/"' . $article . '"/');
    

    希望对你有帮助:)

    【讨论】:

    • 谢谢............我尝试过,但当我尝试它时,我没有当前目录的“..”。但既然你说这是对的,我添加了 .. 并且它成功了,谢谢
    最近更新 更多