开发者

PHP <<< (multi-line handler?) question

I have some code as follows:

$query = <<<QUERY
SELECT
    *
FROM
    names
WHERE
    create_date > date('Y-m-d H:i:s');
QUERY

How can I put the date(开发者_如何学Python'Y-m-d H:i:s') in there without breaking out of the <<< statement?


You could store that piece of code in a variable and use substitution.

$now = date('Y-m-d H:i:s');
$query = <<<QUERY
SELECT
    *
FROM
    names
WHERE
    create_date > $now;
QUERY;

(Example: http://www.ideone.com/pKSVF)



$date = date('Y-m-d H:i:s');
$query = <<<QUERY
SELECT
    *
FROM
    names
WHERE
    create_date > $date
QUERY

http://en.wikipedia.org/wiki/Here_document#PHP

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜