【问题标题】:Is it possible for PHP to specify a particular future date and time, then echo HTML?PHP 是否可以指定特定的未来日期和时间,然后回显 HTML?
【发布时间】:2014-10-08 11:28:56
【问题描述】:

基本上,我希望 PHP 引用特定日期,然后将下面的 HTML 回显到与该日期对应的日历上的相应表格单元格中,即指定 2014 年 8 月 16 日,然后回显事件信息. 你们太快了,我还没准备好,哈! :)

我已经设法制作了一个只使用 PHP 和 CSS 的日历,而且它似乎运行得很好。 呼! 我也想完全避免使用 Javascript 并绕过数据库,到目前为止我已经设法做到了。

我可以使用 CSS 工具提示来显示事件,并让它们与 IOS 一起使用。这是我的最后一个障碍:PHP 是否可以指定一个特定的日期,比如 2014 年 8 月 16 日,然后回显下面的 HTML,让它出现在适合日期的表格单元格中?

<div class="has-tooltip">
Event
<span class="tooltip">Concert In The Park<br />
123 City Park Drive<br />
AnyTown, STATE 00000<br />
<a href="http://example.com" target="_blank">More Info</a><br />
or call 555.123.4567<br /></span>
</div>

没有其他用户将输入信息;它仅供我个人使用,我总是可以在发布前仔细检查。

出现在我的日历页面上的唯一实际的硬编码 HTML 是 &lt;body&gt;&lt;/body&gt;。其他一切都由 PHP 响应,所以我不能很好地将上面的内容添加到现有的表格单元格中。

感谢您的帮助! :)

日历的 PHP 代码(无标签):

$currMonth = isset($_GET['month']) ? $_GET['month']  : date('n');
$currYear  = isset($_GET['year'])  ? $_GET['year']   : date('Y');
$today = (($currYear == date('Y')) && ($currMonth == date('n'))) ? date('j') : 0;

$prevMonth = $currMonth==1 ? 12 : $currMonth-1;
$nextMonth = $currMonth==12?  1 : $currMonth+1;
$prevYear = $currMonth==1 ? $currYear-1 : $currYear;
$nextYear = $currMonth==12? $currYear+1 : $currYear;


$day1 = mktime(0,0,0,$currMonth,1,$currYear);
$dim = date('t', $day1);
$dayN = mktime(0,0,0,$currMonth,$dim,$currYear);
$dow1 = (date('w',$day1)+0) % 7;
$dowN = (date('w',$dayN)+0) % 7;
$calHead = date('F Y',$day1);
echo <<<EOT
    <div class="calwrapper">
    <div class="caltitle"><h1>Calendar</h1></div>
    <div class="container">
    <div class="fnl first"></div>
    <div class="adjust"></div>
     <div class="fnl last"></div>
     </div>
     <div class="caldisplay">
    <table cellspacing="0">
    <tr>
      <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$prevYear&month=$prevMonth"> Prev </a></td>
      <td colspan="5" class="adjust">$calHead</td>
      <td class="hd"><a class="cal_button" href="$_SERVER[PHP_SELF]?year=$nextYear&month=$nextMonth"> Next </a></td>
    </tr>
    <tr>
      <th class="we">Sun</th>
      <th class="wd">Mon</th>
      <th class="wd">Tue</th>
      <th class="wd">Wed</th>
      <th class="wd">Thu</th>
      <th class="wd">Fri</th>
      <th class="we">Sat</th>
     </tr>
    <tr>
EOT;

for ($d=0;$d<$dow1;$d++) echo "<td class=\"hd\"> </td>";
$c = $dow1;
for ($d=1; $d<=$dim; $d++, $c++) {
    if ($c%7==0) echo "</tr><tr>";
    $cl = ($c%7==5) || ($c%7==6) ? 'we' : 'wd';
    $st = ($d == $today) ? "style='padding: 0px;'" : '';
    echo "<td class=\"$cl\" $st>\n";
    echo "$d" ;
    echo "</td>\n";
}
while ($c++ % 7 != 0) echo '<td class=\"hd\"> </td>';
echo "</tr></table>\n";
echo '</div></div>';

【问题讨论】:

  • 我发现你的问题真的很令人困惑。我想我需要更多的上下文。我认为如果您发布更多代码会有所帮助。
  • 我同意凯的观点,需要更多信息...听起来好像有 2 个主题。让 php 给出一个未来的日期并通过 php echo 添加这个 html 到那个特定的日期......我正确吗?
  • &lt;?php $date = date("l jS \of F Y h:i:s A");?&gt; 然后&lt;div class="has-tooltip"&gt;&lt;?php echo $date;?&gt;...&lt;/div&gt; 如果这就是你要问的。未来日期$date = new DateTime("2014-08-16"); $date-&gt;modify("+7 day"); echo $date-&gt;format("Y-m-d");
  • 任何人都可以解释为什么这个问题即使不清楚,也能得到支持。
  • 很抱歉;试图弄清楚董事会是如何工作的,哈!我可以在这里发布我的 PHP 代码吗?

标签: php date time calendar echo


【解决方案1】:

您可以在 for...while 循环中执行此操作:

if (date('d/m/y') == '16/08/14') {
    echo 'Your table cell here';
}

您可以在此处找到有关日期功能的更多信息,http://php.net/manual/en/function.date.php

【讨论】:

  • 非常感谢,伙计们!雾正在消散,我非常感谢 Fred 和 Kenyon 的建议。这将为我排序。 :)
  • 如果此答案对您有帮助或对您有用,请将其标记为已接受的答案?谢谢!
猜你喜欢
  • 1970-01-01
  • 2020-04-14
  • 2012-05-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-25
相关资源
最近更新 更多