分享两个偶尔比较实用的php函数代码:
(1)PHP获得指定日期所在星期的第一天和最后一天,具体代码如下:
<p>function getdays($day){</p> $lastday=date('Y-m-d',strtotime("$day Sunday"));<br /> $firstday=date('Y-m-d',strtotime("$lastday -6 days"));<br /> return array($firstday,$lastday);<br />}<br /><p>print_r(getdays('2012-06-2'));</p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/ai/1045">
<img src="https://img.php.cn/upload/ai_manual/001/503/042/68b6cb9c65c0c805.png" alt="讯飞智作-讯飞配音">
</a>
<div class="aritcle_card_info">
<a href="/ai/1045">讯飞智作-讯飞配音</a>
<p>讯飞智作是一款集AI配音、虚拟人视频生成、PPT生成视频、虚拟人定制等多功能的AI音视频生产平台。已广泛应用于媒体、教育、短视频等领域。</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="讯飞智作-讯飞配音">
<span>67</span>
</div>
</div>
<a href="/ai/1045" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="讯飞智作-讯飞配音">
</a>
</div>
(2)PHP获得指定日期所在月的第一天和最后一天
<p>function getdays($day){</p> $firstday = date('Y-m-01',strtotime($day));<br /> $lastday = date('Y-m-d',strtotime("$firstday +1 month -1 day"));<br /> return array($firstday,$lastday);<br /><br />}<br />print_r(getdays('2012-06-2'));
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号