在字符串中运行一个函数

时间:2011-06-02 18:00:08

标签: php function

如何在字符串中运行一个函数,如下面php中所示:

echo "This page is under construction
      <br/><br/>Current Date: date('l jS \of F Y')";

我使用了双引号字符串语句,但该函数根本没有运行,这是我在运行脚本后在屏幕上得到的结果:

  

此页面正在构建

     

当前日期:日期('l jS \ of F Y')

4 个答案:

答案 0 :(得分:4)

echo "This page is under construction<br/><br/>Current Date:" . date('l jS \of F Y');

答案 1 :(得分:1)

PHP不支持嵌入字符串值的函数。该手册在字符串和parsing上有一个很棒的页面。您可以嵌入变量,或者使用函数输出连接字符串。

答案 2 :(得分:1)

您只需要将日期返回值连接到字符串:

echo "This page is under construction<br/><br/>Current Date: " . date('l jS \of F Y')";

在PHP中。用于字符串连接。

答案 3 :(得分:1)

强制性的你可以随便做的回答:

$date = "date";
echo "This page is under construction<br/><br/>Current Date: {$date('l jS \of F Y')}";

但当然字符串连接是明智的选择。