将php日期输出转换为word? [重复]

This question already has an answer here:

Is there a built in function in PHP that can convert date to string?

I have already tried

date("M jS, Y", strtotime("2014-04-12"));

but our client don't want this output.

Say I have a php variable holding date

$dateToday = '2014-04-12'

I want the output in this format: "Four April Two Thousand and Fourteen" or it could be "April four two thousand and fourteen"

Is there any PHP built in function through which I can do this? If not please suggest me how can I achieve this.

</div>

There is not such parameters for date() function, it's not so hard to convert this manually.

I assume you have the day, month and year in a variable.

  • Create an array with the name of the numbers 1-31,
  • Create an array with the names of the months between 1 and 12,
  • Create an array which holds the numbers between 1 and 99, for the years.

Concatenate these three things with spaces, and you have your output. There are also libraries which do this for you on the internet.

You can simple substract the month,the year and the date separately and use a switch case for each.

This is how I did it.

$dateToday = '2014-04-12';
$year = substr($dateToday, 0, 4);
$month = substr($dateToday, 5, 2);
$date = substr($dateToday, 8, 2);
echo $dateToday.'<br/>';
switch($year) {
    case 2014 : $year_word = 'Two Thousand And Fourteen';
    //You can add as many years as you want
}
switch($month) {
    case 04 : $month_word = 'April';
    //You can add cases from 1 to 12
}
switch($date) {
    case 12 : $date_word = 'Twelve';
    //You can add cases from 0 to 31
}
$dateToday_new = $date_word.' '.$month_word.' '.$year_word;
echo $dateToday_new;

I hope this helps you. :)

Use pear package Numbers_Words:

$dateToday = '2014-04-12';
$date = date('d-F-Y', strtotime($dateToday));
list($day, $month, $year) = explode('-', $date);

$NumbersWords = new Numbers_Words();
$dateWord = implode(' ', array(
    $NumbersWords->toWords($day),
    $month,
    $NumbersWords->toWords($year)
));

echo ucwords($dateWord);