douhuang2218
2016-01-20 09:35
浏览 100
已采纳

fwrite到文档和fgets从它

Info: I am trying to read and write to a file at the same time, but if i have r+ it will only write and if i only have r it will only read, but i need it do both so it can get the info into the document and the info out of it to a cmd window.

Question: Is there i way i can do this and that both will work?

$outputMXA = shell_exec($commandMXA);
$fhMXA = fopen('MXA.txt','r+');
fwrite($fhMXA,$outputMXA);

$MXA = fgets($fhMXA);

图片转代码服务由CSDN问答提供 功能建议

信息:我正在尝试同时读取和写入文件, 但是,如果我有 r + 它只会写,如果我只有 r 它只会读取,但我需要它同时执行这两个所以它可以将信息输入到文档中 从它到cmd窗口的信息。

问题:我能否做到这一点,两者都能正常工作?

  $ outputMXA  = shell_exec($ commandMXA); 
 $ fhMXA = fopen('MXA.txt','r +'); 
 nfwrite($ fhMXA,$ outputMXA); 
 
 $ MXA = fgets($ fhMXA); 
    
 
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dongyan8929 2016-01-20 09:49
    已采纳

    Try this :

    $outputMXA = shell_exec($commandMXA);
    $fhMXA = fopen('MXA.txt','rw');
    fwrite($fhMXA,$outputMXA);
    
    $MXA = fgets($fhMXA);
    fclose($fhMXA);
    

    Edit:

    Or you must separate both actions :

    $outputMXA = shell_exec($commandMXA);
    $fhMXA = fopen('MXA.txt','w+');
    fwrite($fhMXA,$outputMXA);
    fclose($fhMXA);
    
    $fhMXA = fopen('MXA.txt','r+');
    $MXA = fgets($fhMXA);
    fclose($fhMXA);
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题