Home  >  Article  >  Backend Development  >  In PHP, what do %s and %d mean?

In PHP, what do %s and %d mean?

jacklove
jackloveOriginal
2018-05-22 14:56:376018browse

In PHP, you often encounter %s and %d. This article will introduce what %s and %d mean?

Parameters used by PHP sprintf() function

printf - Output formatted string

sprintf() function writes the formatted string into a variable.

%% - Returns the percent symbol

%b - Binary number

%c - Character according to ASCII value

%d - Signed decimal number

%e - Continuous notation (e.g. 1.5e 3)

%u - Unsigned decimal number

%f - Floating point number (local settings aware)

%F - floating point number (not local settings aware)

%o - octal number

%s - string

%x - hexadecimal Number (lowercase letters)

%X - Hexadecimal number (uppercase letters)

<?php
$str = "Hello";
$number = 123;
$txt = sprintf("%s world.  number %d",$str,$number);
echo $txt;
?>

Output:

Hello world. number 123

this This article will explain what %s and %d mean. For more related content, please pay attention to the PHP Chinese website.

Related recommendations:

think php5 multi-table query paging to get the total number of code methods

php commonly used functions processing functions Analysis

PHP The simplest way to verify logged in users (basic form user verification)

The above is the detailed content of In PHP, what do %s and %d mean?. For more information, please follow other related articles on the PHP Chinese website!

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