Home >Backend Development >PHP Tutorial >php I wrote this little experiment, but it didn't work?

php I wrote this little experiment, but it didn't work?

WBOY
WBOYOriginal
2016-08-29 08:50:571107browse

Excuse me, where did I write something wrong?

<code>$txt = "R:/1.txt";

date_default_timezone_set("PRC");


fOpen( $txt  ,"a+" );


for($i=0;$i<10 ;$i++)
{
    $str = date("Y-m-d H:i:s",Time());
    sleep(2);
    fwrite( $txt , $str );
}

fClose( $txt );
</code>

Reply content:

Excuse me, where did I write something wrong?

<code>$txt = "R:/1.txt";

date_default_timezone_set("PRC");


fOpen( $txt  ,"a+" );


for($i=0;$i<10 ;$i++)
{
    $str = date("Y-m-d H:i:s",Time());
    sleep(2);
    fwrite( $txt , $str );
}

fClose( $txt );
</code>

Um, the first parameter of fwrite is the file handle. What you are passing here is a path

<code class="php">
$txt = "R:/1.txt";

date_default_timezone_set("PRC");


//打開文件返回一個文件句柄,
$headle = fopen( $txt  ,"a+" );


for($i=0;$i<10 ;$i++)
{
    $str = date("Y-m-d H:i:s",time());
    sleep(2);
    fwrite($headle , $str );
}

fClose( $txt );
</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn