在txt文件Linux命令行上显示php输出

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 ?

Wouldn't you just run the script and redirect it to the .txt file? Something like

php blacklist.php > blacklist.txt

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

php blacklist.php > blacklist.txt

you can use file_put_contents()

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

I think yes it's possible. you just need make a function to convert it to .txt file

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