首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何将PHP_Beautifier集成到NuSphere PHPed集成开发环境中?

如何将PHP_Beautifier集成到NuSphere PHPed集成开发环境中?
EN

Stack Overflow用户
提问于 2009-07-12 09:58:13
回答 2查看 1.7K关注 0票数 2

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2009-07-12 12:20:59

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

步骤5中的注意事项:

代码语言:javascript
复制
<?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

引用文档:

代码语言:javascript
复制
  // 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。因此,让我们创建脚本:

代码语言:javascript
复制
<?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包,我就可以给出一个更明确的答案。

票数 4
EN

Stack Overflow用户

发布于 2010-03-16 04:18:38

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

代码语言:javascript
复制
    // 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();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1115684

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档