Answer the question
In order to leave comments, you need to log in
How to insert the name of two months on the page?
PHP page. It is necessary to write the name of the current and next month.
For example, in the phrase "... for August and September " you need the current and next month and in the case (!). How to do it correctly, in php or js?
Answer the question
In order to leave comments, you need to log in
$months = array(
1 => 'января',
2 => 'февраля',
...
12 => 'декабря'
);
echo $months[date('n')]; // текущий месяц
echo $months[date('n', strtotime('+1 month')]; // следующий месяц
I do something like this in JS
function getMonth (index, modify) {
var monthesRule = [
['(ь|й)', 'я'],
['т', 'та']
],
result = [
'Январь',
'Февраль',
'Март',
'Апрель',
'Май',
'Июнь',
'Июль',
'Август',
'Сентябрь',
'Октябрь',
'Ноябрь',
'Декабрь'
][index - 1];
if (modify) {
for (var i = 0, r; i < monthesRule.length; i++) {
r = new RegExp(monthesRule[i][0] + '$');
if (r.test(result)) {
return result.replace(r, monthesRule[i][1]);
}
}
}
return result;
}
console.log(getMonth(2));
console.log(getMonth(2, true));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question