Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

fscanf()

Definition and Usage

The input from an open file is parsed using the format defined by the fscanf() function.

Note: Whitespace in the input stream and the format string match exactly. This indicates that a single space character in the input stream can match a tab (\t) in the format string.

Syntax

fscanf(fileformatmixed)

Parameter Values

 

Parameter

Description

file

Essential. indicates which file to check for rephrasing

format

Required is the parameter description file. Indicates which file to check for formatEssential. describes the format.

Potential values for the format:

  • %% – Returns a percent sign
  • %b – Binary number
  • %c – The character according to the ASCII value
  • %d – Signed decimal number
  • %e – Scientific notation (e.g. 1.2e+2)
  • %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 (uppercase letters)

These go in front of the letter (%.2f, for example) and the %.

  • + (Forces both + and – in front of numbers. By default, only negative numbers are marked)
  • ‘ (Specifies what to use as padding. Default is space. Must be used together with the width specifier. Example: %’x20s (this uses “x” as padding)
  • – (Left-justifies the variable value)
  • [0-9] (Specifies the minimum width held of to the variable value)
  • .[0-9] (Specifies the number of decimal digits or maximum string length)

mixed

Rephrase Optional

Technical Details

Return Value:

The read string; if it fails, FALSE

PHP Version:

4.0.1+