printf/sprintf (was regular expression functions)

From: Date: Sat, 02 Sep 2000 07:59:19 +0000
Subject: printf/sprintf (was regular expression functions)
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-2387@lists.php.net to get a copy of this message
pigfai wrote: > Why we use the printf( ) and sprintf( ) to display something instead of > using echo sometimes? What is the usefulness? This is hard to explain :) printf and sprintf give you much more control over how the text that you are outputting is formatted. Using them, you can convert from one number base to another, force the decimal precision of a number, right or left pad a string with spaces, etc... For example: # Convert decimal number to hex $number = 12; printf ('I was a decimal number of %d, but now I am the hex number %X', $number, $number); # Left pad a string with 40 . (minus the length of the string) printf ("%s%'.40s", $column_name, $value); Read the manual entries on sprintf and printf very carefully, then play around with them. :) Good Luck! - Zak

« previous php.windows (#2387) next »