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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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. |
|
|||
|
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 |
|
|||
|
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? |