/*
* 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
?>