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

WBOY
Release: 2016-08-29 08:50:57
Original
1083 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template