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

Store printf value inside variable?

P: n/a
Boo
Using printf, I can get the output I want:

printf("ch:\t6%u\n",$ch);

The %u allows me to convert a negative value to an unsigned decimal
number.

My problem is that I don't want to output this to the screen. I need
to store it as a variable. Is there any way to do this? Thanks!

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


P: n/a

Boo wrote:
Using printf, I can get the output I want:

printf("ch:\t6%u\n",$ch);

The %u allows me to convert a negative value to an unsigned decimal
number.

My problem is that I don't want to output this to the screen. I need
to store it as a variable. Is there any way to do this? Thanks!


Take a look at sprintf() <http://www.php.net/sprintf/>

Ken

Jul 17 '05 #2

P: n/a
Have you looked at the manual?
See also http://www.php.net/sprintf

same as printf, only returns the string

Jul 17 '05 #3

P: n/a
Boo wrote:
Using printf, I can get the output I want:

printf("ch:\t6%u\n",$ch);

The %u allows me to convert a negative value to an unsigned decimal
number.

My problem is that I don't want to output this to the screen. I need
to store it as a variable. Is there any way to do this? Thanks!


I'm new to PHP so can't absolutely answer your question. But, as I
understand it, PHP was designed taking ideas and methods from Perl, C++,
and various other languages. Most all have an sprintf function. Search
the manual for sprintf and I'll bet you've found exactly what you are
looking for.

--
Stan McCann "Uncle Pirate" http://stanmccann.us/pirate.html
Webmaster/Computer Center Manager, NMSU at Alamogordo
Coordinator, Tularosa Basin Chapter, ABATE of NM; AMA#758681; COBB
'94 1500 Vulcan (now wrecked) :( http://motorcyclefun.org/Dcp_2068c.jpg
A zest for living must include a willingness to die. - R.A. Heinlein
Jul 17 '05 #4

P: n/a
Ken Robinson wrote:
Boo wrote:
Using printf, I can get the output I want:

printf("ch:\t6%u\n",$ch);

The %u allows me to convert a negative value to an unsigned decimal
number.

My problem is that I don't want to output this to the screen. I need
to store it as a variable. Is there any way to do this? Thanks!

Take a look at sprintf() <http://www.php.net/sprintf/>

Ken


I should have read on before my initial reply, I knew there had to be an
sprintf funtion.

--
Stan McCann "Uncle Pirate" http://stanmccann.us/pirate.html
Webmaster/Computer Center Manager, NMSU at Alamogordo
Coordinator, Tularosa Basin Chapter, ABATE of NM; AMA#758681; COBB
'94 1500 Vulcan (now wrecked) :( http://motorcyclefun.org/Dcp_2068c.jpg
A zest for living must include a willingness to die. - R.A. Heinlein
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.