如何在PHP中回显定义值?

时间:2016-08-08 06:42:44

标签: php echo

我的代码在这里:

<?php define("SITENAME","Page TITLE");?>

我想回复定义值,如:

<?php echo "<?=SITENAME?>";?>

有人会告诉我怎么做?

2 个答案:

答案 0 :(得分:2)

您可以回显常量的值,如下所示

define("SITENAME","Page TITLE");
echo SITENAME.': My New Content Here';

这给出:Page TITLE: My New Content Here

更多参考:

define("CONSTANT", "Hello world.");
echo CONSTANT; // outputs "Hello world."
echo Constant; // outputs "Constant" and issues a notice.

define("GREETING", "Hello you.", true);
echo GREETING; // outputs "Hello you."
echo Greeting; // outputs "Hello you."

// Works as of PHP 7
define('ANIMALS', array(
    'dog',
    'cat',
    'bird'
));
echo ANIMALS[1]; // outputs "cat"

答案 1 :(得分:1)

你走了:

<?php 
    define("SITENAME","Page TITLE");    
    echo "My website title: ".SITENAME; 
?>

输出:My website title: Page TITLE