IMPRESS dotted_line CONTACT dotted_line search dotted_line Kontakt dotted_line sitemap dotted_line print
324 PHP-Resource users online

Switch to another languags Deutsch aktuelle Sprache Englisch

PHP Manual


(PHP 4 >= 4.0.1, PHP 5)

sscanfParses input from a string according to a format


mixed sscanf ( string $str , string $format [, mixed &$... ] )

The function sscanf() is the input analog of printf(). sscanf() reads from the string str and interprets it according to the specified format, which is described in the documentation for sprintf().

Any whitespace in the format string matches any whitespace in the input string. This means that even a tab \t in the format string can match a single space character in the input string.



The input string being parsed.


The interpreted format for str, which is described in the documentation for sprintf() with following differences:

  • Function is not locale-aware.
  • F, g, G and b are not supported.
  • D stands for decimal number.
  • i stands for integer with base detection.
  • n stands for number of characters processed so far.


Optionally pass in variables by reference that will contain the parsed values.

Return Values

If only two parameters were passed to this function, the values parsed will be returned as an array. Otherwise, if optional parameters are passed, the function will return the number of assigned values. The optional parameters must be passed by reference.

If there are more substrings expected in the format than there are available within str, -1 will be returned.


Example #1 sscanf() Example

// getting the serial number
list($serial) = sscanf("SN/2350001""SN/%d");
// and the date of manufacturing
$mandate "January 01 2000";
$month$day$year) = sscanf($mandate"%s %d %d");
"Item $serial was manufactured on: $year-" substr($month03) . "-$day\n";

If optional parameters are passed, the function will return the number of assigned values.

Example #2 sscanf() - using optional parameters

// get author info and generate DocBook entry
$auth "24\tLewis Carroll";
$n sscanf($auth"%d\t%s %s"$id$first$last);
"<author id='$id'>

See Also

  • fscanf() - Parses input from a file according to a format
  • printf() - Output a formatted string
  • sprintf() - Return a formatted string

Comments to the PHP manual
Write new comment


New Tutorial entries

Migration einer PHP 5 App auf PHP 7

Dieses PHP 7 Tutorial zeigt dir, wie du dein PHP5 Script auf PHP7 umstellst.

Berni | Category: PHP
PHP 7 Virtual Machine

Dieser Artikel zielt darauf ab, einen Überblick über die Zend Virtual Machine, wie es in PHP 7 gefunden wird.

Berni | Category: PHP
plotting masters - a professional guide - Teil II

Grafische Interpolation und Bestapproximation von numerischen Wertepaaren: Wir wollen Punkte auf einer Zeichenebene über verschiedene Verfahren miteinander verbinden.

EVAMasters | Category: PHP