Jump to content

[SOLVED] number formatting


The Little Guy

Recommended Posts

I have a string like this: "Wednesday August 13, 2008 at 1:06 pm"

 

the string will all ways change, but the format will always be the same.

 

In the above string, I would like to take the 13 and do a function on it.

 

Here is what I have:

$mDate = date("l F d, Y \a\\t g:i a" ,filemtime('tos.php'));
echo preg_replace("~\s[0-9](.+?),~",' '.ordinal("$1").',',$mDate);

 

What it is doing is taking the string and adding a th, st, nd, and so on after the 13 or 12 or 1 or what ever it may be.

 

single digits are formatted with one char not 2 so one is 1 not 01.

 

my out put is as follows with that above code:

 

Wednesday August 3th, 2008 at 1:06 pm

 

As you can see it cut off the 1. Why?

Link to comment
https://forums.phpfreaks.com/topic/119544-solved-number-formatting/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.