How to add a tag in PHP date format

Is there a way to add line breaks in PHP date formats? I am using a WordPress plugin that allows you to use regular PHP date formats and have tried many options, but have not yet gotten something to work.

What I tried:

  • l </br> j M
  • l \ nj M

Thanks!

+8
php datetime
source share
5 answers
 echo date("l<\b\\r>j M"); 

or

 echo date('l<\b\r>j M'); 

Outputs:

 Wednesday<br>2 Jan 
+31
source share

You need to avoid the HTML tag to avoid parsing it as date segments:

 <?php echo date('l \<\/\b\r\> j M'); ?> 

Alternatively, if you don't like the above (like me), you can use the strftime () function:

 <?php echo strftime('%A<br />%e %b'); ?> 

The second parameters of the date() and strftime() functions take a timestamp.

+8
source share
 date('l<\b\\r />j M') 

Enter a date string, for example:

 l<br />j M 

What comes out:

 Wednesday<br />2 Jan 
0
source share

Thank you all for your submissions. Then I came across additional documentation where I could use dates like this. Surely your answers will come to my mind again;)

The plugin I use is an event dispatcher, and this is a solution for others who might want this:

  <div class="ev_body"> <span class="ev_icon">#_CATEGORYIMAGE</span> <span class="ev_category">#_CATEGORY</span> <span class="ev_weekday">#l</span> <span class="ev_day">#j</span> <span class="ev_month">#M</span> <span class="ev_time">#_EVENTTIMES</span> <span class="ev_link">#_EVENTLINK {has_location}<br/><i>#_LOCATIONNAME, #_LOCATIONTOWN #_LOCATIONSTATE</i>{/has_location} </span> </div> 

Where #l, #j, #M etc. are PHP date formats.

0
source share

In date() function of the PHP manual page is the following paragraph:

You can prevent recognition of a recognized character in a format string by escaping the previous backslash. If the backslash character is already a special sequence, you may also need to avoid the backslash.


To use the format of your example, correctly escaped characters will look like this:

 'l<\b\r/>j M' "l<\\b\\r/>j M" 

The second example is a double escape code, since \b and \r are significant escape sequences in double-quoted strings.

0
source share

All Articles