fscanf函数使用方法

来源:互联网 发布:linux安装论坛 编辑:程序博客网 时间:2024/06/05 17:42

fscan()函数用于从文件中格式化输入, 把获取到的每一行用空白符分隔(任何空白符,如\t, \n, \r, \f, \v等)成数组,并且返回,如:

文件t1.txt的内容为:renren    kaixin qq  sina,sohu

代码:

$fp    = fopen('t1.txt', 'r');
while ($buffer = fscanf($fp, "%s\r%s\t%s\t%s\t%s")) {
    print_r($buffer);
}
fclose($fp);

输出:

Array
(
    [0] => renren
    [1] => kaixin
    [2] => qq
    [3] => sina
    [4] => sohu
)