首页 > 语言 > PHP > 正文

PHP实现将多个文件中的内容合并为新文件的方法示例

2024-05-04 23:57:56
字体:
来源:转载
供稿:网友

本文实例讲述了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";  }}

希望本文所述对大家PHP程序设计有所帮助。


注:相关教程知识阅读请移步到PHP教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选