Home >Backend Development >PHP Tutorial >Summary of 4 functions for PHP to output content to the browser, PHP browser output function_PHP tutorial

Summary of 4 functions for PHP to output content to the browser, PHP browser output function_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:13:551036browse

Summary of 4 functions for PHP to output content to the browser, PHP browser output function

Copy code The code is as follows:




/*
* 0x01: print() statement
* int print(arguments);
* The print() statement outputs the data passed into it to the browser
*/
print("

I love PHP!!!

");
print "

I love PHP!!!

";
?>
/*
* 0x02: echo() statement, the function is the same as the print() function
* They all output data to the browser
* The efficiency of the echo() function in executing output is slightly better than that of the print() function, because echo does not return a result
*/
echo "

I love PHP!!!

";
$languge="Java";
echo "

I love $languge!!!

";
?>

/*
* 0x03: printf() statement
* If you want to output a mixture of any static text and dynamic information stored in one or more variables, using the printf() function is ideal
* The printf() function divides static data and dynamic data into two parts, and its form is as follows:
* integer printf(string format [,mixed args]);
*/
printf("

I love %s!!!

","C#");
/*
* In the above example, %s is a placeholder. Commonly used placeholders are listed below
* Type Description
* %b Treat the parameter as an integer and display it as a binary number
* %c considers the parameter to be an integer and displays it as the corresponding ASCII character
* %d Treat the parameter as an integer and display it as a signed decimal number
* %f considers the parameter as a floating point number and displays it as a floating point number
* %o Treat the parameter as an integer and display it as an octal number
* %s considers the parameter as a string and displays it as a string
* %u Treat the parameter as an integer and display it as an unsigned integer
* %x considers the parameter to be an integer and displays it as a lowercase hexadecimal number
* %X considers the parameter to be an integer and displays it as an uppercase hexadecimal number
*/
$num=1024;
printf("

%b:%c:%d:%f:%o:%s:%u:%x:%X

",$num,$num,$num,$num ,$num,$num,$num,$num,$num);
?>
/*
* 0x04: sprintf() statement
* The sprintf() function has the same function as the printf function, but it assigns the output value to a string instead of outputting it directly to the browser
* This function is very useful, such as formatting a string containing dynamic output. Combined with the above placeholder, it can also perform hexadecimal conversion. Its form is:
* string sprintf(string format [, mixed args]);
*/
$cost=sprintf("$%.2f",43.2);//$cost=$43.20
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/912670.htmlTechArticleA summary of the four functions of PHP outputting content to the browser. The copy code of the PHP browser output function is as follows: !DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ww...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn