PHP Function Scanf
PHP sscanf is a predefined function which returns parsed input from a string according to a format. The sscanf() function is the input analog of printf(). Unlike printf(), sscanf() matches any whitespace between the format string and the input string. This means that even a tab (
The sscanf() function accepts three parameters, the input string to parse, a format and one or more variables to store the extracted values in. If only two parameters are passed the data parsed will be returned as an array. If more than two optional parameters are passed, the number of the assigned values will be returned.
There are many different formats supported by sscanf(). The most commonly used are %d for integers, %f for floating point numbers and %s for hexadecimal numbers. There are also several width specifiers for specifying how many decimal digits or maximum string length should be displayed. Other special characters include a sign specifier (- or +) that should be placed in front of a number, and an alignment specifier for displaying the formatted string left or right justified.
The sscanf() function also supports some conversion specifications that differ from the printf() functions. For example sscanf() can be configured to use a different base for converting numbers, or a different separator for decimal numbers. It can also be used to print hexadecimal strings by combining the hexadecimal flag with the special formatting characters.