【问题标题】:How to integrate PHP_Beautifier into NuSphere PHPed IDE?如何将 PHP_Beautifier 集成到 NuSphere PHPed IDE?
【发布时间】:2010-11-10 01:59:56
【问题描述】:

谁能列出在phped中集成PHP_Beautifier的步骤。

【问题讨论】:

    标签: php integration phped php-beautifier


    【解决方案1】:

    You should try the steps located here。这些是集成任何将代码返回到编辑器的脚本的一般步骤。

    第 5 步中的注释:

    <?php
    
    $f = fopen("php://stdin", "r");
    $s = fread($f, 100000); // should be big enough
    fclose($f);
    echo "\"" . $s . "\"";
    
    ?>
    

    这应该被忽略并且相当草率。它类似于其他 PHPed 脚本 posted here 的格式。

    现在来看看如何实际使用 PHP_beautifier,refer to the documentation

    引用文档:

      // Create the instance
      $oBeautifier = new PHP_Beautifier(); 
    
      /* snip optional stuff*/
    
      // Define the input file
      $oBeautifier->setInputFile(__FILE__); 
    
      // Define an output file.
      // $oBeautifier->setOutputFile(__FILE__.'.beautified.php');  No need for this
    
      // Process the file. DON'T FORGET TO USE IT
      $oBeautifier->process();
    
      // Show the file (echo to screen)
      $oBeautifier->show();
    
      // Save the file
      //$oBeautifier->save(); No Need for this.
    

    好的,所以我们需要给它一个文件,但是我查看了 Beautifier.php 主文件,它似乎以某种方式接受了 STDIN。所以让我们编写脚本:

    <?php
    
    class BeautifyCode
    {
    
        public function run()
        {
            require_once('path/to/Beautifier.php'); // It's the main file in the PEAR package
    
            // Create the instance
            $oBeautifier = new PHP_Beautifier();
    
            // Define the input file
            // I believe you leave blank for STDIN, looking through the code **
            $oBeautifier->setInputFile();
            // If that doesn't work try:
            // $oBeautifier->setInputFile('php://stdin');
    
            $oBeautifier->process();
    
            $oBeautifier->show();
    
            // If that doesn't work, try this:
            // echo utf8_decode($oBeautifier->get());
        }
    
    }
    
    $bc = new BeautifyCode;
    $bc->run();
    
    ?>
    

    所以将它保存为 PHP 文件,然后根据第一个链接的第 3 步调用它。我会安全地使用@php5@,因为 PHP_beautifier 可能需要它。

    我提前道歉,我不确定 PHP_beautifier 如何处理 STDIN 输入。我查看了代码,但无法确定。另一种选择是始终先保存您正在清理的 PHP 文件,然后查看 phpED 文档以了解如何获取您已打开并正在清理的 PHP 文件的路径。

    如果我有更多时间浏览 PHP_beautifier 包,我可以给出更明确的答案。

    【讨论】:

    • 谢谢。我遇到了路径问题。我的美化器存储在 "D:\PHP_Beautifier\Beautifier.php" 我如何在 require_once('path/to/Beautifier.php'); 输入路径;
    【解决方案2】:

    您可以使用 STDIN 和 STDOUT 作为输入或输出

        // Create the instance
        $oBeautifier = new PHP_Beautifier();
    
        // Define the input file
        // I believe you leave blank for STDIN, looking through the code **
        $oBeautifier->setInputFile(STDIN);
        $oBeautifier->setOutputFile(STDOUT);
        $oBeaut->process();
        $oBeaut->save();
    

    【讨论】:

      猜你喜欢
      • 2010-11-09
      • 1970-01-01
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-16
      • 1970-01-01
      相关资源
      最近更新 更多