7

I currently have a blacklist.php file that generates a black list and I need a blacklist.txt file on Linux that pulls the output from the PHP file.

Is this possible?

2
  • so you want to write data from php to text file ..of course it is possible Commented Mar 26, 2013 at 4:46
  • file_put_contents... Commented Mar 26, 2013 at 4:47

4 Answers 4

11

If your blacklist.php writes output to standard output, you can run your PHP script like this

php blacklist.php > blacklist.txt
Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't work if I insert it in windows' scheduled tasks.
3

We can do it using file_put_contents

<?php
file_put_contents('blacklist.txt ', file_get_contents('blacklist.php'));  
?>

Another alternative: Use exec()

<?php
exec ('php blacklist.php', $output); 
file_put_contents('blacklist.txt', $output); 
?>

Another alternative:Output redirection to a text file using Command line

In Windows:

C:\xampp\php>php C:\xampp\htdocs\blacklist.php >blacklist.txt

In Linux:

$ php blacklist.php >blacklist.txt

Comments

2

You can use file_put_contents():

file_put_contents('your file', 'your data')

Comments

1

Just run the script and redirect it to the .txt file. Something like

php blacklist.php > blacklist.txt

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.