fscanf() 每行都根据格式循环输出
最后更新于:2022-04-02 02:30:08
[TOC]
## 示例
items.txt
```
coins 5
pens 6
chairs 12
books 20
```
```
$fh = fopen("a.txt", "r");
if ($fh === false) {
exit("Cannot read file\n");
}
while ($data = fscanf($fh, "%s %d")) {
list($item, $quantity) = $data;
echo "$item: $quantity\n";
//coins: 5
//pens: 6
//chairs: 12
//books: 20
}
fclose($fh);
```
';