谁能列出在phped中集成PHP_Beautifier的步骤。
发布于 2009-07-12 12:20:59
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包,我就可以给出一个更明确的答案。
发布于 2010-03-16 04:18:38
可以使用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();https://stackoverflow.com/questions/1115684
复制相似问题