Categories
Code PHP

Simple PHP Script to Pluralize Month names

You often need to refer to a Month’s name in the Plural, Eg, “I want Junes Database back up” or “Display Marches Orders”. 

Here is a very simple PHP function to show the nice Pluralized month, simply don’t pass in a param to show hte current months plural, or pass in the PHP Date’s ‘n’ ( n Numeric representation of a month, without leading zeros – 1 through 12)

<?php 

function pluralize_month($month = NULL) {

		if((int)$month < 1 or (int)$month > 12) $month = date('n'); 
		if($month == 3) return 'Marches';
		return date('F', strtotime(date('Y-'.$month.'-01'))). 's';

	}

Leave a Reply

Your email address will not be published. Required fields are marked *