gpt4 book ai didi

php - 如何在php中回显循环并将其放入变量中?

转载 作者:行者123 更新时间:2023-11-30 09:00:23 25 4
gpt4 key购买 nike

您好,我在将数据从 php 发送到 pdf 时遇到了问题。我认为唯一的方法是将要发送到 pdf 函数的数据放入变量中。这是我需要放入 php 变量中的代码..

<table width="95%" height="95%">
<tr>
<td align="center">
<table width="100%" border="0" cellpadding="2" cellspacing="2">
<tr align="center">
<td colspan="7" bgcolor="#2561cf" style="color:#FFFFFF"><strong><?php echo $monthNames[$cMonth-1].' '.$cYear; ?></strong></td>
</tr>
<tr>
<td align="center" bgcolor="#2561cf" style="color:#FFFFFF"><strong>Sun</strong></td>
<td align="center" bgcolor="#2561cf" style="color:#FFFFFF"><strong>Mon</strong></td>
<td align="center" bgcolor="#2561cf" style="color:#FFFFFF"><strong>Tue</strong></td>
<td align="center" bgcolor="#2561cf" style="color:#FFFFFF"><strong>Wed</strong></td>
<td align="center" bgcolor="#2561cf" style="color:#FFFFFF"><strong>Thu</strong></td>
<td align="center" bgcolor="#2561cf" style="color:#FFFFFF"><strong>Fri</strong></td>
<td align="center" bgcolor="#2561cf" style="color:#FFFFFF"><strong>Sat</strong></td>
</tr>

<?php
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
$startday = $thismonth['wday'];

for ($i=0; $i<($maxday+$startday); $i++) {
$day = ($i - $startday + 1);
if($day['1'] == '1' || $day['1'] == '2' || $day['1'] == '3' || $day['1'] == '4' || $day['1'] == '5' || $day['1'] == '6' || $day['1'] == '7' || $day['1'] == '8' || $day['1'] == '9'){
$day = '0'.$day;
}else{
$day = $day;
}
$date = $monthNames[$cMonth-1].' '.$day.', '.$cYear;
$date2 = $cMonth.'/'.$day.'/'.$cYear;
$events = $this->getEvents($date2);
if(($i % 7) == 0 ) echo "<tr>\n";
if($i < $startday) echo "<td></td>\n";
else echo "<td valign='top' align='left' width='50px' height='50px'><div class='".$dateId."' id='".$date."' title='".$date2."' style='cursor:pointer;'>". ($i - $startday + 1) .'</div>'. $events."</td>\n";
if(($i % 7) == 6 ) echo "</tr>\n";
}
?>
</table>
</td>
</tr>
</table>

最佳答案

如果您有大量的 HTML/PHP 并且您需要将输出存储在变量中而不是打印到屏幕上,您可以使用 output buffering使这变得容易的功能:

<?php
ob_start(); // Start the buffer (nothing will be output)
?>
<p>Lots and lots of mixed <?php echo 'HTML'; ?> and PHP...</p>
<?php
$content = ob_get_clean(); // End the buffer and assign everything to $content
?>

关于php - 如何在php中回显循环并将其放入变量中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9732598/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com