我正在研究一个php代码,它以php显示月份。
<script>
document.getElementById('title_fr').value = "<?php setlocale(LC_TIME, "frc"); echo strftime("%d %B %Y", strtotime( $this_date )); ?>";
</script>
上面的 php 代码返回法语的月份名称,如下所示。
janvier
février
mars
avril
mai
juin
juillet
août
septembre
octobre
novembre
décembre
问题陈述:
我想知道我需要在上面的 php 代码中进行哪些更改,以便对于一个月中的几天,如果 d = "1",则替换"1er">
我想我需要在这里进行一些更改echo strftime("%d %B %Y", strtotime( $this_date ));
但我不确定确切的位置。
我在 %d 之后添加了 er,但它在每月的每一天之后都添加了 er。
获取日期数字,如果是1
则附加er
。
<?php
setlocale(LC_TIME, "frc");
$this_time = strtotime( $this_date );
$day = date('d', $this_time);
$suffix = $day == 1 ? 'er' : '';
$formatted = strftime("%d$suffix %B %Y", $this_time);
?>
document.getElementById('title_fr').value = "<?php echo $formatted; ?>";