For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > March 2005 > Store printf value inside variable?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Store printf value inside variable?
Boo

2005-03-30, 3:58 am

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!

Ken Robinson

2005-03-30, 3:58 am


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

BKDotCom

2005-03-30, 3:58 am

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

same as printf, only returns the string

Uncle Pirate

2005-03-30, 3:58 am

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
Uncle Pirate

2005-03-30, 3:58 am

Ken Robinson wrote:
> Boo wrote:
>
>
>
> 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
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2010 codecomments.com