我想更新 html 中的 div,以便每周仅使用 php 而不使用 cron 来显示不同的内容。 怎么可能实现它?以下代码为每2个月第10天激活码 但我想逻辑会有所不同。如果可能的话,一些提示或例子会很棒!我很乐意听取您的意见!
// check if current day is 10th and month is an even number
if (date('d')==10 && date('m') % 2 == 0) {
// get todays-date (format: yyyymmdd)
$today = date('Ymd');
// get info about last run
$last_run = variable_get('my_last_run', 0);
// check last run was not today
if ($last_run!=$today) {
// set last run to today
variable_set('my_last_run', $today);
/* Place your code here */
}
}
最佳答案
我刚刚更新了您的示例,现在它将在每个下周一运行:
$weekInYearNumber = (int)date('W');
$weekDayNumber = (int)date('w');
if ($weekDayNumber === 1 && $weekInYearNumber % 2 == 0) {
// Rest of your code.
}
关于php - 如何在没有 Crontab 的情况下每 2 周在 PHP 中调用一个方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43671971/