2011-11-03 43 views
0

我喜欢在我的PHP脚本运行时向shell输出很多细节。什么是从PHP输出新行到shell的最佳方式?

我有很多线路是这样的:

echo "\n\n" . __method__ . " - PDF file does not exist."; 

它错误的地狱了我,有这么多的\n到处都是在我的代码。有一个更好的方法吗?也许有什么简单的东西我错过了?

什么是一些首选的方法来做到这一点在一些主要的PHP库?

+1

你可以自己写一些'writeln()'函数来抑制这些很多新行。 –

回答

3

PHP中没有标准的方法。

但是你可以写一个函数来做到这一点....

function shellprint($string) 
{ 
    echo($string . "\n"); 
} 
1

心中已经测试做的这个和其他的方式,但没有奏效。

它的工作原理是有像

 if ($something==true) 
     { 
      echo 'Hello 
This is a new line. 
and this another new line'; 
     } 

我想对我的代码一个不错的缩进风格生锈方式,所以我创建了一个小功能来解决这个问题。

function shecho($text) { 
    $text = str_replace('\n', ' 
', $text); 
    echo $text; 
} 

这样,我将只需要编写

shecho ('Hello\nThis is a new line.\nand this another new line'); 

简单的东西。
希望它可以帮助任何人!

相关问题