The Little Guy Posted August 13, 2008 Share Posted August 13, 2008 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 More sharing options...
effigy Posted August 13, 2008 Share Posted August 13, 2008 Use "l F dS, Y \a\\t g:i a". Link to comment https://forums.phpfreaks.com/topic/119544-solved-number-formatting/#findComment-615900 Share on other sites More sharing options...
The Little Guy Posted August 13, 2008 Author Share Posted August 13, 2008 I would like to place <sup></sup> tags around the th how can I do that? Link to comment https://forums.phpfreaks.com/topic/119544-solved-number-formatting/#findComment-615904 Share on other sites More sharing options...
effigy Posted August 13, 2008 Share Posted August 13, 2008 echo date('l F d<\s\u\p>S</\s\u\p>, Y \a\t g:i a', time()); Link to comment https://forums.phpfreaks.com/topic/119544-solved-number-formatting/#findComment-615907 Share on other sites More sharing options...
The Little Guy Posted August 13, 2008 Author Share Posted August 13, 2008 OH, WOW, didn't know you could do that, that is sweet, Thanks! Link to comment https://forums.phpfreaks.com/topic/119544-solved-number-formatting/#findComment-615909 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.