php替换字符串中的几月和几号

发布时间:2022-02-12 14:08:55    发布者:文昌文城莱奥网络技术工作室    浏览次数:592

$month_first_location = mb_stripos("福星高照12月11日爆码", "月");
echo $month_first_location;
echo '<br>';
//echo stripos("abcdef","f");
$first_char_before_month = mb_substr("福星高照12月11日爆码", $month_first_location - 1, 1);
echo $first_char_before_month;
echo '<br>';
$second_char_before_month = mb_substr("福星高照12月11日爆码", $month_first_location - 2, 1);
echo $second_char_before_month;

dump(is_numeric($second_char_before_month));

if (is_numeric($second_char_before_month)) {
    $month_replaced = $second_char_before_month . $first_char_before_month;
}else{
    $month_replaced = $first_char_before_month;
}

echo $month_replaced;
echo '<br>';
$current_month = date('n',time());
echo $current_month;
echo '<br>';
$after_the_replacement_month = str_replace($month_replaced,$current_month,"福星高照12月11日爆码");
echo $after_the_replacement_month;
echo '<br>';
$month_first_location2 = mb_stripos($after_the_replacement_month, "月");
echo $month_first_location2;
echo '<br>';
$day_first_location = mb_stripos($after_the_replacement_month, "日");
echo $day_first_location;
echo '<br>';
$day_replaced = mb_substr("$after_the_replacement_month", $month_first_location2 + 1, ($day_first_location - $month_first_location2) -1);
echo $day_replaced;
echo '<br>';
$current_day = date('d',time());
echo $current_day;
$after_the_replacement_day = str_replace($day_replaced,$current_day,"福星高照12月11日爆码");
echo '<br>';
echo $after_the_replacement_day;