这篇文章主要介绍了PHP实现将多个文件中的内容合并为新文件的方法,涉及php编码转换、文件与目录的遍历以及文件读写相关操作技巧,需要的朋友可以参考下
本文实例讲述了PHP实现将多个文件中的内容合并为新文件的方法。分享给大家供大家参考,具体如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | function test()
{
$hostdir = iconv( "utf-8" , "gbk" , "C:\Users\原万里\Desktop\日常笔记" ) ;
$filesnames = scandir( $hostdir );
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中文网其他相关文章!