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
精彩评论