zoukankan      html  css  js  c++  java
  • 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 "
    ";
        }
        }
    
  • 相关阅读:
    11、sqlite
    10、正则
    9、bs4
    8、异常与import
    7、文件
    6、函数
    4、字典及集合
    3、元组
    1、python基本语法
    shell编程 15 --- shell 脚本调试技巧
  • 原文地址:https://www.cnblogs.com/yuanwanli/p/6629549.html
Copyright © 2011-2022 走看看