fwrite到文档和fgets从它

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

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

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

$ MXA = fgets($ fhMXA);
</ code> </ pre>
</ div>

展开原文

原文

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);

php
douguachi0056
douguachi0056 r+是读/写两者。或者可以使用x+
4 年多之前 回复

1个回答



试试这个:</ p>

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

$ MXA = fgets($ fhMXA);
nclclose($ fhMXA);
</ 代码> </ pre>

编辑:</ p>

或者您必须分开两个动作:</ p>

  $ outputMXA =  shell_exec($ commandMXA); 
$ fhMXA = fopen('MXA.txt','w +');
nfwrite($ fhMXA,$ outputMXA);
nclclose($ fhMXA);

$ fhMXA = fopen( 'MXA.txt','r +');
$ MXA = fgets($ fhMXA);
nclclose($ fhMXA);
</ code> </ pre>
</ div>

展开原文

原文

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);

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问