Date Problem with \n

This is a discussion on Date Problem with \n within the PHP General forums, part of the PHP Programming Forums category; Small issue with formatting a date. If I type in this: echo date("g:i:s a \o\n ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 08-13-2007
Kevin Murphy
 
Posts: n/a
Default Date Problem with \n

Small issue with formatting a date. If I type in this:

echo date("g:i:s a \o\n l F j, Y");

the "n" character in the word "on" doesn't appear, but instead what I
get is a new line in the source code. If I type it as:

echo date("g:i:s a \on l F j, Y");

I get the number 8 (current month) where the n is supposed to be.

Is there any way to get an "n" in there?

--
Kevin Murphy
Webmaster: Information and Marketing Services
Western Nevada College
www.wnc.edu
775-445-3326

P.S. Please note that my e-mail and website address have changed from
wncc.edu to wnc.edu.



Reply With Quote
  #2 (permalink)  
Old 08-13-2007
Jim Lucas
 
Posts: n/a
Default Re: [PHP] Date Problem with \n

Kevin Murphy wrote:
> Small issue with formatting a date. If I type in this:
>
> echo date("g:i:s a \o\n l F j, Y");
>
> the "n" character in the word "on" doesn't appear, but instead what I
> get is a new line in the source code. If I type it as:
>
> echo date("g:i:s a \on l F j, Y");
>
> I get the number 8 (current month) where the n is supposed to be.
>
> Is there any way to get an "n" in there?
>


Use single quotes, then your \n will not be converted to a NL char

--
Jim Lucas

"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare
Reply With Quote
  #3 (permalink)  
Old 08-13-2007
Richard Lynch
 
Posts: n/a
Default Re: [PHP] Date Problem with \n

On Mon, August 13, 2007 12:50 pm, Kevin Murphy wrote:
> Small issue with formatting a date. If I type in this:
>
> echo date("g:i:s a \o\n l F j, Y");
>
> the "n" character in the word "on" doesn't appear, but instead what I
> get is a new line in the source code. If I type it as:
>
> echo date("g:i:s a \on l F j, Y");
>
> I get the number 8 (current month) where the n is supposed to be.
>
> Is there any way to get an "n" in there?


As noted, apostrophes will work in this case.

If you need to embed a variable, however, you may want to re-read this
from the manual a couple times:


"You can prevent a recognized character in the format string from
being expanded by escaping it with a preceding backslash. If the
character with a backslash is already a special sequence, you may need
to also escape the backslash."

So, for example:

date("g:i:s a \o\\n l F j, Y");

Here's what happens:

PHP's string parser "eats" the "\\" and turns it into a single
back-slash: "\"

*THEN* you have "\n" being passed to the C date() function, which then
"eats" the "\n" and says:
This is then not the "n" for "Numeric representation of a month,
without leading zeros" but just a regular old "n" as text.

--
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 08:41 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0