Outputting Data to the Browser Flashcards
What three functions can be used to output data to the browser?
- print()
- echo()
- printf()
Write a plausible PHP print statement
Write a plausible echo statement
When should a programmer use the printf() statement?
The printf() statement is ideal when you want to output a blend of static text and dynamic information stored within one or several variables.
Write a plausible printf() statement
printf(“Bar inventory: %d bottles of tonic water.”, 100);
%b specifies…
binary number
%c specifies…
a character corresponding to a ASCII value
%d specifies…
a signed decimal number
%f specifies …
a floating-point number
%o specifies…
an octal number
%s specifies…
a string
%u specifies…
an unsigned integer
%x specifies…
a lower-case hexadecimal number
%X specifies…
an upper-case hexadecimal number
What’s the difference between printf() and sprintf()?
The sprintf() statement is functionally identical to printf() except that the output is assigned to a string rather than rendered to the browser.