PHP - 附加的 html 字符串被截断

PHP - Appended html string being cut off

我正在生成一些 html 以与 MPDF php 库一起使用以生成 PDF。但是当我用 php 创建一些 HTML 其中有一个循环时,它会切断字符串的开头,这是我的代码:

$page = "<div class='A4'><h1>Test: lookbook</h1><p>";
$page .= $date;

$page .= "</p><div class='items'>";

while ($the_query->have_posts()) {
    $the_query->the_post();
    $page .= "<img src='";
    $page .= get_field('product_image')['url'];
    $page .= "'>";
}
$page .= "</div></div><div class='footer'>A Story in every gemstone</div>";

echo $page;

运行上面的代码returns:

1<img src='urltoimage'></div></div><div class='footer'>A Story in every gemstone</div>

所以看起来 while 循环之前的所有内容都被删除了。

$page 是 The Loop 中存在的 Wordpress 全局变量。

https://codex.wordpress.org/Global_Variables

WordPress-specific global variables are used throughout WordPress code for various reasons. Almost all data that WordPress generates can be found in a global variable.

While inside the loop, these globals are set, containing information about the current post being processed.

...

$page (int) The page of the current post being viewed. Specified by the query var page.