Printf command printing unwanted carriage return

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Percipient
Forum Newbie
Posts: 1
Joined: Fri Aug 17, 2007 12:02 pm

Printf command printing unwanted carriage return

Post by Percipient »

I have a very small segment of code that's been bothering me for a while but not enough for me to really do anything about it until now.

My problem is, I'm using a printf command to print a formatted decimal, but there's an unwanted carriage return (two, actually) in there, so instead of getting
"Number: [5.02]"
I get
"Number:[
5.02
]"

using essentially the code below

Code: Select all

<? echo("Number: ["); 
?><div id="blah"><?
						printf('%03.1f',($test));
?></div><? echo(']'); ?>
I made sure to get rid of white spaces in between the ending php tag and the html div's just in case....I'm figuring it's something with printf that inserts a carriage return like that by default. Is there some way to disable or counteract this?

Any help appreciated, thanks!

--Tony
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

It is not a printf() error, it is an HTML error ;)

DIV is block element, not inline. Use SPAN.
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

DIV is block element...
... thus it visually starts on a new line
It is not a printf() error, it is an HTML error
Not an error per se, actually.
Post Reply