Jump to content

Gameboyz's Php Queries


gameboyz
 Share

Recommended Posts

try this one: http://ca.php.net/manual/en/function.sprintf.phpThe difference is whether the integer is signed and + or -.
Hi thanks, but how do you apply those optional specifiers under the format parameter? The link doesn't really teach, say how to apply a padding. And how do you understand the prototype eg:
string sprintf  ( string $format  [, mixed $args  [, mixed $...  ]] )

Link to comment
Share on other sites

Sometimes you can learn more from the examples than the explanation. Examples 5-6 of sprintf() in the manual answer some of your questions. Just scroll down. Usually there's also a complete explanation of the prototype's arguments and return value, also. In the case of sprintf(), there's a good explanation of the format argument, but you can only understand the other arguments by looking at the examples.If you haven't figured it out by now, mixed means that the function accepts/returns different kinds of variables. Could be a string, number, or array. Like str_replace will accept a string or array.Memorization comes with time and experience. Variable types, operators, and flow controllers come first, because you use them all the time. Functions is a different matter, because there are so many of them. If you use a lot of string functions, say, you start to remember how they work, and how one is different from another. Studying is okay, but the best thing is just to program something. There are a couple tricks to using the online manual. One, if you add a function name to the end of the manual's web address (like: http://us.php.net/str_replace) you'll get redirected to the function's description. That's real nice. Two, if you're looking at the description of a string function (for example), the left side of the page has a breadcrumb menu showing where you are. 1 level up, there's a link to a page that links you to ALL string functions. That's useful for finding just the right function to match any situation. And the more you look at the list, the more you remember what's there.

Link to comment
Share on other sites

Hi thanks, but how do you apply those optional specifiers under the format parameter?
The format parameter is the string to print, followed by each value to replace in the string. Check the documentation for printf also. printf is the output function in C, if you do a search for it online you'll find a ton of documentation (it's probably one of the more documented functions in programming).echo sprintf("This is a signed int: %d \nThis is an unsigned int: %u \nThis is a string: %s", -100, 50, 'test string');
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...