Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

fwrite - Why output of this php program is not correct

I'm trying to add prefixes and suffixes to some words. I did not write in the code, it is clear how the prefix and suffix are written, but my output is wrong. What is my code problem and how can I fix it? I will write my code and outputs below my php code :

<?php

$file = fopen("en-up.txt","r");
$afile = fopen("newa.txt","w");
$bfile = fopen("newb.txt","w");
$cfile = fopen("newc.txt","w");
while(! feof($file))
  {
$pishvandVApasvand = array("@@","@3210","@321","@32","@23",/* and a lot more */); 
$line = fgets($file);
    foreach ($pishvandVApasvand as $piv) {
        $a = "$piv$line";
        $b = "$line$piv";
        $c = "$piv$line$piv";

        fwrite($afile,$a);
        fwrite($bfile,$b);
        fwrite($cfile,$c);
      }
  
  }
fclose($file);
fclose($afile);
fclose($bfile);
fclose($cfile);

my input file is somthing like this :

Abandon
aBANDON
aBaNdOn
abandon
Ability
aBILITY
aBiLiTy
ability
Able
aBLE
aBlE
able
AbOuT
About
aBOUT
about
AbOvE
Above
aBOVE
above
AbSeNt
Absent
aBSENT
absent
Absorb
aBSORB
aBsOrB
absorb
AbStRaCt
... ( 9000 line )

and here is my output :

file newa :
@@Abandon
@3210Abandon
@321Abandon
@32Abandon
@23Abandon
@210Abandon
@21Abandon
@123Abandon
@12Abandon
@1Abandon
@0123Abandon
@012Abandon
@01Abandon
@Abandon
32@Abandon
321@Abandon
...

and file newb :

Abandon
@@Abandon
@3210Abandon
@321Abandon
@32Abandon
@23Abandon
@210Abandon
@21Abandon
@123Abandon
@12Abandon
...

and file newc :

@@Abandon
@@@3210Abandon
@3210@321Abandon
@321@32Abandon
@32@23Abandon
@23@210Abandon
@210@21Abandon
@21@123Abandon
@123@12Abandon
@12@1Abandon
@1@0123Abandon
@0123@012Abandon
@012@01Abandon
@01@Abandon
@32@Abandon
32@321@Abandon
321@3210@Abandon
...

my question is Why newb file as Word + suffix is not ?

Also why newc file as Prefix + word + suffix is not ? Note : i try to do it with file_put_contents but result is same at all

question from:https://stackoverflow.com/questions/65936354/why-output-of-this-php-program-is-not-correct

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...