PHP printf Function

What is printf Function and how it is used in string?


The printf function is used to output a formatted string in PHP.



In the above syntax "format" specifies the format of the string to be output,in which user can include the following formatting characters " %% ,%b, %c, %d, %e, %u, %f, %F, %o, %s, %x, %X ", "arg1" is the argument inserted in the first % sign, "arg2" in the second % sign, "arg++" is optional value can be inserted in third and fourth % signs.

Example :

$str = "HIOX INDIA";
$number = 365;
printf("%s provides web hosting services %u days",$str,$number);
Result :

HIOX INDIA provides web hosting services 365 days

In the above example a string is stored in "$str" ,a number in "$number", one can use the print formatting for strings by "%s" and for a numerals by "%u" .

PHP Topics

Ask Questions

Ask Question