【问题标题】:Display php output on a txt file Linux command line在 txt 文件 Linux 命令行上显示 php 输出
【发布时间】:2013-03-15 19:15:19
【问题描述】:

我目前有一个生成黑名单的 blacklist.php 文件,我需要一个 Linux 上的 blacklist.txt 文件,它可以从 PHP 文件中提取输出。

这可能吗?

【问题讨论】:

  • 所以你想将数据从php写入文本文件..当然可以
  • file_put_contents...

标签: php linux shell command-line centos


【解决方案1】:

只需运行脚本并将其重定向到 .txt 文件。类似的东西

php blacklist.php > blacklist.txt

【讨论】:

    【解决方案2】:

    如果您的 blacklist.php 将输出写入standard output,您可以像这样运行您的 PHP 脚本

    php blacklist.php > blacklist.txt
    

    【讨论】:

    • 如果我将它插入到 windows 的计划任务中,这将不起作用。
    【解决方案3】:

    你可以使用file_put_contents():

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

    【讨论】:

      【解决方案4】:

      我们可以使用file_put_contents来做到这一点

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

      另一种选择:使用exec()

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

      另一种选择Output redirection to a text file using Command line

      Windows 中:

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

      Linux 中:

      $ php blacklist.php >blacklist.txt
      

      【讨论】:

        猜你喜欢
        • 2021-02-01
        • 1970-01-01
        • 1970-01-01
        • 2023-03-14
        • 2019-05-20
        • 2016-07-16
        • 2017-01-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多