This article mainly introduces the PHP implementation of the content of multiple files into a new file method, involving PHP encoding conversion, file and directory traversal and file read and write related operation skills, the need for friends can refer to the next
The code is as follows:
function test () { $hostdir = iconv ("Utf-8", "GBK", "C:\Users\ original miles \desktop\ daily Notes"),//iconv () convert encoding, UTF-8 to GBK, If the error is GBK after adding//ignore $filesnames = Scandir ($hostdir); the//scandir () function returns an array of files and directories in the specified directory. Default ascending order, foreach ($filesnames as $name) { if ($name! = ":" && $name! = "). There will be more '. ' In the traversal results. And ' ... ', no use, no treatment; { $cipath = $hostdir. $name; $cjfilenames = Scandir ($cipath); Depending on the situation, decide again whether to traverse the foreach ($cjfilenames as $cjname) { if ($cjname! = ":" && $cjname! = ") again. & &!is_dir ($cipath. " /". $cjname) " { $str = file_get_contents ($cipath. ") /". $cjname); File_put_contents ("E:/test.txt", $str, file_append); }}} echo "\ n"; }}
Related recommendations:
Python implements two file merge functions
JS How to achieve project construction and file merging ?
C # file merge code