[英]define and heredoc
taken from the documentation regarding strings 取自关于字符串的文档
DEFINE('PREFIX','/holiday');
$const = PREFIX;
echo <<<EOD
<img src="{$const}/images/hello.png" />
EOD;
if you have more than 1 constant, variable usage would be difficult. 如果你有超过1个常数,那么变量的使用会很困难。 so try this method
所以尝试这种方法
define('PREFIX', '/holiday');
define('SUFFIX', '/work');
define('BLABLA', '/lorem');
define('ETC', '/ipsum');
$cname = 'constant'; // if you want to use a function in heredoc, you must save function name in variable
$body = <<<EOD
<img src="{$cname('PREFIX')}/images/hello.png" />
<img src="{$cname('SUFFIX')}/images/hello.png" />
<img src="{$cname('BLABLA')}/images/hello.png" />
<img src="{$cname('ETC')}/images/hello.png" />
EOD;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.