YouTip LogoYouTip

Func String Sscanf

# PHP sscanf() Function [![Image 3: PHP String Reference](#) PHP String Reference](#) ## Example Parse a string: [Run Example Β»](#) * * * The sscanf() function parses input from a string according to a specified format. The sscanf() function parses a string into variables based on a 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 those variables. If the number of specifiers is greater than the number of variables containing them, an error will occur. However, if the number of specifiers is less than the number of variables containing them, the extra variables will contain NULL. Related functions: - Output a formatted string - Write a formatted string to a variable * * * ## Syntax sscanf(_string,format,arg1,arg2,arg++_) | Parameter | Description | | --- | --- | | _string_ | Required. Specifies the string to read. | | _format_ | Required. Specifies the format to use. Possible format values: * %% - Returns a percent sign % * %c - Character corresponding to ASCII value * %d - Signed decimal number (negative, 0, positive) * %e - Scientific notation (lowercase, e.g. 1.2e+2) * %u - Unsigned decimal number (greater than or equal to 0) * %f - Floating-point number * %o - Octal number * %s - String * %x - Hexadecimal number (lowercase letters) * %X - Hexadecimal number (uppercase letters) Additional format values. Must be placed between % and the letter (e.g. %.2f): * + (Prepend + or - to define the sign of the number. By default, only negative numbers are marked, positive numbers are not marked) * ' (Specifies what to use as padding. Default is space. Must be used with a width specifier. Example: %'x20s (use "x" as padding)) * - (Left-justify the variable value) * (Specifies the minimum width of the variable value) * . (Specifies the number of decimal places or maximum string length) **Note:** If multiple format values are used, they must be used in the order shown above, not mixed. | | _arg1_ | Optional. The first variable to store data. | | _arg2_ | Optional. The second variable to store data. | | _arg++_ | Optional. The third, fourth variables to store data. And so on. | ## 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 those variables. If the number of specifiers is greater than the number of variables containing them, an error will occur. However, if the number of specifiers is less than the number of variables containing them, the extra variables will contain NULL. | | :--- | | PHP Version: | 4.0.1+ | * * * ## More Examples ## Example 1 Using format values %s, %d, and %c: [Run Example Β»](#) * * PHP String Reference](#)
← Func String StrnatcmpFunc String Sprintf β†’