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:
Parameter |
Description |
Required/Optional |
string |
Specify the string to read. |
Required |
format |
Specify 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 |
arg1 |
Specify first variable to store data |
Optional |
arg2 |
Specify second variable to store data |
Optional |
arg++ |
Specify third , fourth and so on. |
arg++ |
Example 1
Output:
Example 2
Output:
Example 3
Output:
Example 4
Output:
Array
(
[0] => We
[1] => are
[2] => Learning
[3] => PHP
[4] => 7
)
|