Previously, I heard from my teacher that the sprintf () function must use the echo method to display the formatted string and output. next I will take a look at the simple method. when I read some documents, I always see the following code example code: $ qu... previously, I heard from my teacher that the sprintf () function must use the echo method to display the formatted string and output. next I will take a look at the simple method.
I am reading some documents and always see the following code when reading books:
The instance code is as follows:
$query = sprintf('INSERT INTO %sUSER (USERNAME, PASSWORD, ' . 'EMAIL_ADDR, IS_ACTIVE, PERMISSION) VALUES ("%s", "%s", "%s", %d, %d)', DB_TBL_PREFIX, mysql_real_escape_string($this->username, $GLOBALS['DB']), mysql_real_escape_string($this->password, $GLOBALS['DB']), mysql_real_escape_string($this->emailAddr, $GLOBALS['DB']), $this->isActive, $this->permission);
Sprintf is used to format the string. Is there any difference between this writing method and the writing method connected directly with a string connector? or is this more rigorous?
The syntax format of the printf () and sprintf () functions is:
int printf(string $format[,mixed $arg1[,mixed args2...]])string sprintf(string $format[,mixed $arg1[,mixed args2...]])
In a small example, the instance code is as follows:
Differences between echo, print, printf, and sprintf in PHP
"; $number=print $str."
"; echo $number."
"; $format="%b%c%d"; $number1=printf($format,88,88,88); echo "
".$number1; echo "
".sprintf($format,88,88,88); ?>
Introduction to echo, print, printf, and sprintf
The returned value in print output mode is int type, and the returned value is always 1. the syntax format of print is as follows:
Int print (string $ str)
The echo output method does not return values. the syntax format of echo is as follows:
Void echo (string $ str [, string $ str1. ..])
In PHP, echo and print can be used in general cases, but in some cases, the two methods are also different, as shown in:
1) echo supports multiple parameters, but print only supports one parameter.
2) The return value of echo is void, and that of print is always 1.