0

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.

3
  • where exactly do you run into problems ? Can you read the content of existing files ? Can you create new file ? Commented Jan 29, 2013 at 11:18
  • Here's all you need. ;) Commented Jan 29, 2013 at 11:21
  • i can create result.txt**(**result.txt is not present before script is executed.) i can not get content out of one.txt or two.txt Commented Jan 29, 2013 at 12:30

1 Answer 1

4

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");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.