Microsoft Word - Core PHP Programming Using PHP to Build Dynamic Web Sites

(singke) #1

<?
echo "First string", 2, 3.4, "last string";
?>


flush()


As text is sent to the browser via functions like print and echo, it may be stored in a
memory buffer and written out only when the buffer fills. The flush function attempts to
force the buffer to be dumped to the browser immediately. Since the Web server
ultimately controls communication with the browser, the flush may not be effective.


If your script takes a long time to execute, it's a good idea to output a status message and
flush the buffer. This keeps the user from clicking away.


<?
//simulate long calculation
//flush output buffer with each step
for($n=0; $n5; $n++)
{
print("Calculating...
");
flush();
sleep(3);
}
print("Finished!
");
?>


print(string output)


The output argument of print is sent to the browser.


<?
print("hello world!BR>\n");
?>


printf(string format,.. .)


The printf function converts and outputs arguments to the browser based on a format
string. The format string contains codes, listed in Table 8. 1, for different data types.
These codes begin with a percentage sign, %, and end with a letter that determines the
type of data. The codes match up with a list of values that follow the format string in the
argument list. Any text outside these codes will be sent unchanged to the browser.

Free download pdf