php入門學(xué)習(xí)知識點六PHP文件的讀寫操作代碼

字號:


    php入門學(xué)習(xí)知識點六PHP文件的讀寫操作代碼,讀取文件內(nèi)容可以用以下兩個函數(shù)進行操作fread,file_get_contents
    代碼如下:
    <?php
    //打開文件
    $fp=fopen('tmp.html','r');
    //讀取文件內(nèi)容可以用以下兩個函數(shù)進行操作fread,file_get_contents
    $str=fread($fp,filesize('tmp.html'));//filesize為獲取文件大小
    $content=file_get_contents('tmp.html');
    //寫文件
    $news=fopen('news.html','w');
    fwrite($news,$content);
    //關(guān)閉文件流
    fclose($fp);
    fclose($news);
    echo$content;
    ?>