Latest web development tutorials

PHP fscanf () function

PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual

Definition and Usage

fscanf () function according to the specified format for input from an open file to parse.

grammar

fscanf(file,format,mixed)

参数 描述
file 必需。规定要检查的文件。
format 必需。规定格式。

可能的格式值:

  • %% - 返回一个百分号 %
  • %b - 二进制数
  • %c - ASCII 值对应的字符
  • %d - 包含正负号的十进制数
  • %e - 科学计数法(例如:1.2e+2)
  • %u - 不包含正负号的十进制数
  • %f - 浮点数(本地属性)
  • %F - 浮点数(非本地属性)
  • %o - 十进制数
  • %s - 字符串
  • %x - 十六进制数(小写字母)
  • %X - 十六进制数(大写字母)

附加的格式值。必需放置在 % 和字母之间(例如 %.2f):

  • + (在数字前面加上 + 或 - 来定义数字的正负性。默认情况下,只有负数才做标记,正数不做标记)
  • ' (规定使用什么作为填充,默认是空格。它必须与宽度指定器一起使用。例如:%'x20s(使用 "x" 作为填充))
  • - (左调整变量值)
  • [0-9] (规定变量值的最小宽度)
  • .[0-9] (规定小数位数或最大字符串长度)

注释:如果使用多个上述的格式值,它们必须按照上面的顺序进行使用,不能打乱。

mixed 可选。


Tips and Notes

Note: Blank Blank will match any input stream format string any. This means that the format string tab \ t will match the input stream to a single space character.


PHP Filesystem Reference Manual Complete PHP Filesystem Reference Manual