sscanf definition, usage and analysis_PHP tutorial

WBOY
Release: 2016-07-20 11:02:27
Original
1277 people have browsed it

sscanf definition, usage and analysis
The sscanf() function parses input from a string according to a specified format.

If only two parameters are passed to this function, the data will be returned in the form of an array. Otherwise, if additional parameters are passed, the parsed data will be stored in these parameters. If the number of separators is greater than the number of variables containing them, an error occurs. However, if there are fewer separators than variables, the extra variables contain null.

Grammar
sscanf(string,format,arg1,arg2,arg++) parameter description
string required. Specifies the string to be read.
format required. Specifies the format to be used.
arg1 optional. The first variable to store data.
arg2 optional. A second variable to store the data.
arg++ Optional. The third and fourth variables that store data. And so on.

Description
The format parameter is the format of the conversion, starting with the percent sign ("%") and ending with the conversion character. Possible format values ​​below:

%% - Returns the percent symbol
%b - binary number
%c - character
according to ascii value %d - signed decimal number
%e - Continuous counting method (e.g. 1.5e+3)
%u - unsigned decimal number
%f - floating point number (local settings aware)
%f - floating point number (not local settings aware)
%o - octal number
%s - string
%x - Hexadecimal number (lowercase letters)
%x - Hexadecimal number (capital letters)
Example

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!