Abdul Qadeer
Abdul Qadeer

Reputation: 372

PHP fwrite() function

I am new to programming and i was trying to write a PHP code that could.

1)Create a new file.

2)Add content from two files into that file.

Here is an example of what i am trying to do.

1)I have two files one.txt and two.txt.

2)Content of these two file is as follows.

one.txt=abc123

two.txt=def456

3)I want the following result in result.txt.

 abc123

 this is the result file.

 def456

I have tried doing it alot of different ways that i knew but could not make it work. I am a beginner so having trouble getting started. Thanks.

Upvotes: 0

Views: 74

Answers (1)

Shiplu Mokaddim
Shiplu Mokaddim

Reputation: 57650

If your target is only to wrap the result file just use file_get_contents and file_put_contents.

$content_one = file_get_contents("one.txt");
$content_res = file_get_contents("result.txt");
$content_two = file_get_contents("two.txt");
file_put_contents("result.txt", "$content_one\n$content_res\n$content_two");

Upvotes: 4

Related Questions