-9

重複の可能性:
このテキストファイルの内容を読み取って解析するにはどうすればよいですか?

C++でテキストファイルを読みたい

これがテキストファイルの例です

(item(name 256) (Index 1)(Image "Wea001")   (specialty  (aspeed 700) (Hit 20)))
(item   (name 257)  (desc 520)           (Index 2)  (Image "Wea002")(specialty(Attack 16 24)))

私は次のような出力が欲しい

name : 256
Index : 1
Image : Wea001
Specialty > aspeed : 700 
Specialty > hit : 20

Name : 257
Desc : 520
Index : 2
Image : Wea002
Speciality > Attack : 16 24

それは可能ですか?

4

2 に答える 2

1

PHPマニュアルからまっすぐ:

fgets()

例1 ファイルを 1 行ずつ読み込む

<?php
$handle = @fopen("/tmp/inputfile.txt", "r");
if ($handle) {
    while (($buffer = fgets($handle, 4096)) !== false) {
        echo $buffer;
    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle);
}
?>
于 2012-09-12T20:43:43.333 に答える
0

RTM

<?php
$f = fopen ("fgetstest.php", "r");
$ln= 0;
while ($line= fgets ($f)) {
    ++$ln;
    printf ("%2d: ", $ln);
    if ($line===FALSE) print ("FALSE\n");
    else print ($line);
}
fclose ($f);

?>

于 2012-09-12T20:47:19.637 に答える