The fscanf() function parses input from an open file according to a specified format. It returns the values parsed as an array, if only two parameters were passed.
Syntax
fscanf(file_pointer, format, mixed)
登录后复制
Parameters
file_pointer − A file system pointer resource created using fopen().
format − Specify the format. Here are the values:
%% – Returns a percent%b – Binary number%c – The character according to the ASCII value%f – Floating-point number%F – Floating-point number%o – Octal number%s – String%d – Signed decimal number%e – Scientific notation%u – Unsigned decimal number%x – Hexadecimal number for lowercase letters%X – Hexadecimal number for uppercase letters
mixed − Specify the assigned values. Optional.
立即学习“PHP免费学习笔记(深入)”;
Return
The fscanf() function returns the values parsed as an array, if only two parameters were passed.
Example
<?php $file_pointer = fopen("new.txt", "r"); while ($playerrank = fscanf($handle, "%s%d")) { list ($name, $rank) = $playerrank; echo “$name got rank $rank.”; } fclose($file_pointer);?>
登录后复制
Output
Amit got rank 2
登录后复制
以上就是PHP中的fscanf()函数的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/1694543.html