PHP將多個文件中的內容合並為新的文件


function test()
    {
    $hostdir= iconv("utf-8","gbk","C:\Users\原萬里\Desktop\日常筆記") ;     //iconv()轉換編碼方式,將UTF-8轉換為gbk,若是報錯在gbk后加//IGNORE
    $filesnames = scandir($hostdir);                         //scandir() 函數返回指定目錄中的文件和目錄的數組。默認升序排列,
   
    foreach ($filesnames as $name) {
             if($name!=".." && $name!=".")                   //遍歷結果中會多出‘.’以及‘..’,沒有用處,不予處理;
             {
                 $cipath = $hostdir.$name;
                 $cjfilenames = scandir($cipath);                    //根據情況再決定是否再向下遍歷一次
                 foreach($cjfilenames as $cjname)
                 {
                       if($cjname!=".." && $cjname!="." &&!is_dir($cipath."/".$cjname))
                         {
                             $str = file_get_contents($cipath."/".$cjname);
                             file_put_contents("e:/test.txt",$str,FILE_APPEND);
                         }
                 }
             }
         echo "\n";
    }
    }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM