0

Im new to php and I'm just trying stuff out, and I was wondering if i could take text from one file then put it into another.
For example have a .txt file that contains :

<?php
      echo "Hello World";
?>

but then have a script run that takes that text and puts it into a new .php file.

4
  • I don't get what you are tring to do, Its better to tell us, what you are planning to achive with that, maybe we can offer an better idea. Commented Oct 8, 2016 at 9:06
  • @VuralAcar i was wondering if i can take the content of one file then write it to another file using php Commented Oct 8, 2016 at 9:10
  • You want to get the content from a text file and copy to another text file? Commented Oct 8, 2016 at 9:11
  • @VuralAcar copy it to a php file Commented Oct 8, 2016 at 9:15

2 Answers 2

1

If I understand you correctly, what are you trying to achive is copying a content of a text file to a php file.

Simpliest way to do it:

<?php
   $sourceFile = 'example.txt';
   $destinyFile = 'example.php';

   if (copy($sourceFile, $destinyFile))
      echo "DONE";
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot for this.
0

When you have php code in that file you also could just use:

Include 'example.php';

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.