douxiong4892 2019-01-22 15:30
浏览 39
已采纳

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

I'm generating some html to be used with the MPDF php library for generating a PDF. But when I create some HTML with php which has a loop inside it, it cuts of the beginning of the string, here's my code:

$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;

Running the above code returns:

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

So it looks like everything before the while loop is being cut out.

  • 写回答

1条回答 默认 最新

  • dongnanman9093 2019-01-22 15:41
    关注

    $page is a Wordpress global variable that exists within The Loop.

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 MATLAB四叉树处理长方形tif文件
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址
  • ¥15 elmos524.33 eeprom的读写问题
  • ¥15 使用Java milo连接Kepserver服务端报错?
  • ¥15 用ADS设计一款的射频功率放大器
  • ¥15 怎么求交点连线的理论解?
  • ¥20 软件开发方法学习来了