【问题标题】:Can I use a php constant within a string that is pulled from a database?我可以在从数据库中提取的字符串中使用 php 常量吗?
【发布时间】:2023-03-23 06:53:02
【问题描述】:

我整个晚上都在尝试这样做,但我无法让它工作。

我正在从我的数据库中提取包含其他 PHP 常量的文本字符串,并尝试将整个内容定义为常量,显示代码可能比解释它更容易:

foreach($dalResponse->contents as $thisConfigItem){
    define($thisConfigItem['contentTag'],$thisConfigItem[LANGUAGE_DEFAULT]);
}

在本例中,$thisConfigItem['contentTag'] 的内容是 WELCOME,$thisConfigItem[LANGUAGE_DEFAULT] 的内容是“Welcome to SITE_NAME”。 SITE_NAME 是一个先前定义的常量,其值为“thisSite”。

我希望常量 WELCOME 包含“Welcome to thisSite”。

这可能吗?

干杯 安迪

【问题讨论】:

  • 它没有理由不工作......

标签: php database constants definitions


【解决方案1】:

如果你尝试使用变量的值,尝试使用 variables 变量:

http://php.net/manual/en/language.variables.variable.php

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-22
    相关资源
    最近更新 更多