Using PHP in $html = sting?


Using PHP in $html = sting?

我有下面的代码显示当前YouTube视频通过html嵌入代码。

 <?php
if ( function_exists( 'wpmudev_ppw_html' ) ) {
$html = '<iframe width="560" height="315" src="https://www.youtube.com/embed/-uiN9z5tqhg?wmode=transparent&" frameborder="0" allowfullscreen></iframe>'; // html code to be protected (required)
$id = 1; // An optional unique id if you are using the function more than once on a single page
$description = 'video'; // Optional description of the protected content
$price = '1.50'; // Optional price for a single view. If not set, price set in the post will be applied. If that is not set either, Unit Price in the Global Settings will be used.
echo wpmudev_ppw_html( $html, $id, $description, $price );
}
?>

我想删除YouTube iFrame,并让它显示以下代码代替。

<img class="img-responsive img-thumbnail" src="<?php the_field('macro_map'); ?>" />

但是,$html=行的PHP代码在这样做时会导致语法错误…

$html = '<img class="img-responsive img-thumbnail" src="<?php the_field('macro_map'); ?>" />'; 

首先,这是否可能工作。如果是这样,我做错了什么?

你不能在<?php ?>标签里面有<?php ?>。您将需要删除嵌套的标记,并使用.来连接字符串和函数的返回。

$html = '<img class="img-responsive img-thumbnail" src="' . the_field('macro_map') . '" />';