By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,967 Members | 1,687 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,967 IT Pros & Developers. It's quick & easy.

formatting date() and nbsp;

P: n/a
JS
What I have is a date that I'd like to format to keep it together on
one line using non-breaking spaces.

I started with:
date ("l F j, Y", $unixtime);

and soon realized that the letters n and s are reserved characters for
the date command, so I did this:

$mydate =date ("l&\nb\sp;F&\nb\sp;j,&\nb\sp;Y", $unixtime);

The &, b, and p don't need to be escaped since they aren't listed as
being special characters for the date command. But no go. All it was
insert a new line in the middle to replace the \n and a space for the
\s. But as far as I can tell the space it inserts for the \s isn't
and html non-breaking space.

Then I tried:

$mydate =date ("l"." " . "F" . " ". "j," . " " . "Y",
$unixtime);

But the function does all of the string concatenation before it
substitutes the characters for the time information, so that doesn't
work either.

I know I can go through and use:

$mydate str_replace(" ", " ", $mydate);

but I thought there might be a better way. Surely there's some way to
tell date() that I want the character n, not the numeric
representation of the month and not a new line character.

Any ideas?

Thanks
Jul 16 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"JS" <jd***@hotmail.com> wrote in message
news:b0**************************@posting.google.c om...
What I have is a date that I'd like to format to keep it together on
one line using non-breaking spaces.

I started with:
date ("l&nbsp;F&nbsp;j,&nbsp;Y", $unixtime);

This is not applicable?

$mydate =date ("l F j, Y", $unixtime);

<nobr>$mydate</nobr>

Louise
Jul 16 '05 #2

P: n/a
JS
David Mackenzie <dc*@tarbrax.freeserve.co.uk> wrote:
From the manual ( http://uk2.php.net/date ):
<quote>
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.
</quote>

So
$mydate =date ("l&\\nb\\sp;F&\\nb\\sp;j,&\\nb\\sp;Y", $unixtime);

should do it (untested!)


Thanks. I read the manual page three times and just kept missing it.
Damn these eyes. Too late. ;)

Thanks
Jul 16 '05 #3

P: n/a
On Thu, 07 Aug 2003 10:07:09 GMT, "boclair" <bo*****@bigpond.net.au> wrote:
This is not applicable?

<nobr>$mydate</nobr>


<nobr> is not an HTML element.

http://www.w3.org/TR/html4/index/elements.html

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 16 '05 #4

P: n/a
Andy Hassall wrote:
On Thu, 07 Aug 2003 10:07:09 GMT, "boclair" <bo*****@bigpond.net.au>
wrote:
This is not applicable?

<nobr>$mydate</nobr>


<nobr> is not an HTML element.

http://www.w3.org/TR/html4/index/elements.html


If you want &nbsp; instead of space, the other solution
is to use str_replace on your formatted string
Jul 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.