开发者

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

开发者 https://www.devze.com 2023-01-03 21:38 出处:网络
I have some code as follows: $query = <<<QUERY SELECT * FROM names WHERE create_date > date(\'Y-m-d H:i:s\');

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

精彩评论

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

关注公众号