Formatting Months With AP Stlye

logo_AP_newThe PHP date() class supports a mess-load of different date masks, but developers working with content creators and editors from a journalism background may find the date() class wanting, particularly when it comes to supporting style and usage guides like the AP Stylebook. In particular, AP Style calls for longer month names (Jan., Feb., Aug. Sept. Oct., Nov., Dec.) to be abbreviated, while shorter month names (March, April, May, June, July) remain intact.

I tackled similar AP Style issue realated to how str

So, here’s a quick and dirty function to convert “whole” months to AP Style months:

<?php
//Function to reformat dates (months) to comply with AP Style.
function APdate($datestring){
$APstyleDate = (str_replace(array(
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
"Mar.",
"Apr.",
"Jun.",
"Jul.",
"Sep.",
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec"
),
array(
"Jan.",
"Feb.",
"March",
"April",
"May",
"June",
"July",
"Aug.",
"Sept.",
"Oct.",
"Nov.",
"Dec.",
"March",
"April",
"June",
"July",
"Sept.",
"Jan.",
"Feb.",
"March",
"April",
"May",
"June",
"July",
"Aug.",
"Sept.",
"Oct.",
"Nov.",
"Dec."
), $datestring));
return $APstyleDate;
}
?>

One Reply to “Formatting Months With AP Stlye”

Leave a Reply