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 example in this article describes how the PHP implementation combines the contents of multiple files into a new file. Share to everyone for your reference, 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"; }}