How to concatonate 2 files together
Moderator: General Moderators
How to concatonate 2 files together
I am new to PHP and would like to merge or concatonate 2 text files together. The UNIX equivalent is "cat file1.txt >> file2.txt" Can someone show me an example of how to do this? Thanks.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: How to concatonate 2 files together
If on *nix you can exec() the command:
In PHP this is one way:
Code: Select all
exec('cat /path/to/file1.txt >> /path/to/file2.txt');Code: Select all
file_put_contents('/path/to/file1.txt', file_get_contents('/path/to/file2.txt'), FILE_APPEND);mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: How to concatonate 2 files together
incidentally:
So be careful with that method.
From a rather interesting article.Allowing users to specify any portion of the string you pass to the exec, system, shell_exec, or passthru functions is a huge security risk, and you need to plan carefully in advance before allowing any of this.
So be careful with that method.