Easy Tutorial
❮ Php Filtered Unserialize Func Xml Set Element Handler ❯

PHP sscanf() Function

PHP String Reference Manual

Example

Parse a string:


The sscanf() function parses input from a string according to a specified format. The sscanf() function parses a string into variables based on the format string.

If only two arguments are passed to this function, the data will be returned as an array. Otherwise, if additional arguments are passed, the parsed data will be stored in these arguments. If the number of delimiters is greater than the number of variables that contain them, an error occurs. However, if the number of delimiters is less than the number of variables that contain them, the extra variables will contain NULL.

Related functions:


Syntax

Parameter Description
string Required. The string to be read.
format Required. The format to be used. Possible format values: %% - Returns a percent sign %<br> %c - Character corresponding to the ASCII value<br> %d - Signed decimal number (negative, zero, positive)<br> %e - Lowercase scientific notation (e.g., 1.2e+2)<br> %u - Unsigned decimal number (greater than or equal to 0)<br> %f - Floating-point number<br> %o - Octal number<br> %s - String<br> %x - Hexadecimal number (lowercase)<br> %X - Hexadecimal number (uppercase) Additional format values. Must be placed between % and the letter (e.g., %.2f): + (Adds a + or - sign before the number. By default, only negative numbers are marked, positive numbers are not marked)<br> ' (Specifies what to use as padding. Default is a space. It must be used with the width specifier. For example: %'x20s (uses "x" as padding))<br> - (Left-adjust the value)<br> [0-9] (Specifies the minimum width of the value)<br> .[0-9] (Specifies the number of decimal places or the maximum string length) Note: If multiple format values are used, they must be used in the order shown above, not in a mixed order.
arg1 Optional. The first variable to store the data.
arg2 Optional. The second variable to store the data.
arg++ Optional. The third, fourth, etc., variables to store the data.

Technical Details

Return Value: If only two arguments are passed to this function, the data will be returned as an array. Otherwise, if additional arguments are passed, the parsed data will be stored in these arguments. If the number of delimiters is greater than the number of variables that contain them, an error occurs. However, if the number of delimiters is less than the number of variables that contain them, the extra variables will contain NULL.
PHP Version: 4.0.1+
--- ---

More Examples

Example 1

Using the format values %s, %d, and %c:


❮ Php Filtered Unserialize Func Xml Set Element Handler ❯