Home > Article > Backend Development > sscanf definition, usage and analysis_PHP tutorial
sscanf definition, usage and analysis
The sscanf() function parses input from a string according to a specified format.
If only two parameters are passed to this function, the data will be returned in the form of an array. Otherwise, if additional parameters are passed, the parsed data will be stored in these parameters. If the number of separators is greater than the number of variables containing them, an error occurs. However, if there are fewer separators than variables, the extra variables contain null.
Grammar
sscanf(string,format,arg1,arg2,arg++) parameter description
string required. Specifies the string to be read.
format required. Specifies the format to be used.
arg1 optional. The first variable to store data.
arg2 optional. A second variable to store the data.
arg++ Optional. The third and fourth variables that store data. And so on.
Description
The format parameter is the format of the conversion, starting with the percent sign ("%") and ending with the conversion character. Possible format values below:
%% - Returns the percent symbol
%b - binary number
%c - character
according to ascii value
%d - signed decimal number
%e - Continuous counting method (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 (capital letters)
Example