PHP implementation method to merge content from multiple files into a new file

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.