我有一个php变量:
$output_map[$the_ID]['map'] = '<div class="marker" data-lat="'.$get_google_map['lat'].'"></div>';
我希望下面的代码位于上面var:
中的“marker”div内<p><?php echo $location['address']; ?></p>
<p><?php the_field('description'); ?></p>
<<<EOD
方法不起作用,进入/退出php标签似乎不起作用。看起来它看起来很混乱,我想知道我在这里缺少什么语法?
答案 0 :(得分:0)
试试这个:
<?php
$output_map[$the_ID]['map'] = '
<div class="marker" data-lat="'.$get_google_map['lat'].'">
<p>'.$location['address'].'</p>
<p>'.get_field('description').'</p>
</div>';
答案 1 :(得分:0)
注意在heredoc输出中使用大括号{
和}
。请参阅this answer中的heredoc syntax和示例#3 Heredoc字符串引用示例。
<?php
// Display eventual errors and exceptions.
error_reporting(E_ALL);
ini_set('display_errors', 1); // SET IT TO 0 ON A LIVE SERVER!
// Dummy test function
function the_field($name) {
return 'Some ' . $name . ' value';
}
// Dummy test values.
$the_ID = 1;
$get_google_map['lat'] = '50.2341234';
$location['address'] = 'Some address';
// Build the map item's content.
$output_map[$the_ID]['map'] = sprintf(
'<div class="marker" data-lat="%s">
<p>%s</p>
<p>%s</p>
</div>'
, $get_google_map['lat']
, $location['address']
, the_field('description')
);
// Option 1.
//echo $output_map[$the_ID]['map'];
// ... or Option 2.
echo <<<MAP
{$output_map[$the_ID]['map']}
MAP;
<div class="marker" data-lat="50.2341234">
<p>Some address</p>
<p>Some description value</p>
</div>