PHP String sscanf() Function

The sscanf() is predefined PHP function. It is used to return parses input from a string according to a format. If we will pass two parameters in the function, the data will be returned as an array.

Related Function:

  • print(): It is used for output one or more strings.
  • fprint() : It is used to write a formatted string to a stream.

Syntax:

ParameterDescriptionRequired/Optional
stringSpecify the string to read.Required
formatSpecify the format to use.
  • %% : It returns a percent sign.
  • %c : For ASCII value
  • %d : Signed decimal number.
  • %e : Scientific notation.(e.g. 1.2e+2)
  • %u : Unsigned decimal number
  • %f : Floating-point number
  • %o : Octal number
  • %s : String
  • %x : Hexadecimal number (lowercase letters)
  • %X : Hexadecimal number (uppercase letters) etc.
Required
arg1Specify first variable to store dataOptional
arg2Specify second variable to store dataOptional
arg++Specify third , fourth and so on.arg++

Example 1

Output:

int(7)

Example 2

Output:

int(18)
int(6)

Example 3

Output:

string(10) "javatpoint"

Example 4

Output:

Array
(
    [0] => We
    [1] => are
    [2] => Learning
    [3] => PHP
    [4] => 7
)

Next TopicPHP String




Latest Courses