Ad Code

Formatting the day number suffix in php with date()

What I am trying to output in html:

<p>January, 1<sup>st</sup>, 2011</p>
What I am doing now (feels very heavy) in php:

//I am omitting the <p> tags:
echo date('M j',$timestamp)  
. '<sup>' . date('S', $timestamp) . '</sup>'  
. date(' Y', $timestamp);


You just have to escape characters that are interpreted by the date function.

echo date('M j<\sup>S</\sup> Y'); // < PHP 5.2.2
echo date('M j<\s\up>S</\s\up> Y'); // >= PHP 5.2.2


 

Post a Comment

0 Comments