note 48299 deleted from function.date by betz

From: Date: Sat, 18 Dec 2004 17:02:32 +0000
Subject: note 48299 deleted from function.date by betz
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-81977@lists.php.net to get a copy of this message
Note Submitter: chirpy AT chirpys DOT com ---- A quick function I just knocked up to create the English ordinal suffix of a day that is passed to do it. I'm sure there must be one somewhere, but I can't find it :) <?php function suffix ($day) { $suffices = array("th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th"); $original_formatting = $day; if (strlen($day) == "1") { $day = "0" . $day; } $ending = $day{1}; if ($day{0} != "1") { $thesuffix = $suffices[$ending]; } else { $thesuffix = "th"; } $formatted_day = $original_formatting . $thesuffix; return $formatted_day; } ?> For example: <?php suffix(2); // Returns 2nd suffix(02); // Returns 02nd suffix(17); // Returns 17th ?> It's probably not the most efficient way possible, but it works. Hope it helps somebody :) ---- Reason: bad code

« previous php.notes (#81977) next »